Bonjour

Mon projet consiste à reconnaître les panneau de signalisation le long d'une route. J'ai donc 2 programme: 1 qui permet de détecter les triangle dans le flux de la webcam et un autre qui permet de rechercher le rouge dans le flux de la webcam. Mais je voudrais fusionner c'est 2 programme en 1 en utilisant les appel de fonction mais je ne sais pas comment faire j'ai cherche sur internet met je n'arrive pas.

Je voudrait d'abord détecter la couleur rouge et si il y a du rouge on cherche si il y a un triangle.

J'utilise Microsoft Visual studio 2013 avec la bibliothèque opencv

Mon premier programme qui détecte les triangle
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <iostream>
#include <ctype.h>
#include <sstream>
#include "opencv\cv.h"
#include "opencv\highgui.h"
 
using namespace std;
 
IplImage* imgTracking = 0;
 
int lastX1 = -1;
int lastY1 = -1;
 
int lastX2 = -1;
int lastY2 = -1;
 
void trackObject(IplImage* imgThresh){
    CvSeq* contour;  //hold the pointer to a contour
    CvSeq* result;     //hold sequence of points of a contour
    CvMemStorage *storage = cvCreateMemStorage(0); //storage area for all contours
 
    //finding all contours in the image
    cvFindContours(imgThresh, storage, &contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
 
    //iterating through each contour
    while (contour)
    {
        //obtain a sequence of points of the countour, pointed by the variable 'countour'
        result = cvApproxPoly(contour, sizeof(CvContour), storage, CV_POLY_APPROX_DP, cvContourPerimeter(contour)*0.02, 0);
 
        //if there are 3 vertices  in the contour and the area of the triangle is more than 100 pixels
        if (result->total == 3 && fabs(cvContourArea(result, CV_WHOLE_SEQ))>100)
        {
            //iterating through each point
            CvPoint *pt[3];
            for (int i = 0; i<3; i++){
                pt[i] = (CvPoint*)cvGetSeqElem(result, i);
            }
            //drawing lines around the triangle
            cvLine(imgTracking, *pt[0], *pt[1], cvScalar(255, 0, 0), 4);
            cvLine(imgTracking, *pt[1], *pt[2], cvScalar(255, 0, 0), 4);
            cvLine(imgTracking, *pt[2], *pt[0], cvScalar(255, 0, 0), 4);
        }
 
        //obtain the next contour
        contour = contour->h_next;
    }
 
    cvReleaseMemStorage(&storage);
}
 
 
int main(){
    //load the video file to the memory
    CvCapture* capture = 0;
 
    capture = cvCaptureFromCAM(0);
 
    if (!capture){
        printf("Capture failure\n");
        return -1;
    }
 
    IplImage* frame = 0;
    frame = cvQueryFrame(capture);
    if (!frame) return -1;
 
    //create a blank image and assigned to 'imgTracking' which has the same size of original video
    imgTracking = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
    cvZero(imgTracking); //covert the image, 'imgTracking' to black
 
    cvNamedWindow("Video");
    cvNamedWindow("Videos");
    //iterate through each frames of the video    
    while (true){
 
        frame = cvQueryFrame(capture);
        if (!frame) break;
        frame = cvCloneImage(frame);
 
        //smooth the original image using Gaussian kernel
        cvSmooth(frame, frame, CV_GAUSSIAN, 3, 3);
 
        //converting the original image into grayscale
        IplImage* imgGrayScale = cvCreateImage(cvGetSize(frame), 8, 1);
        cvCvtColor(frame, imgGrayScale, CV_BGR2GRAY);
 
        //thresholding the grayscale image to get better results
        cvThreshold(imgGrayScale, imgGrayScale, 100, 255, CV_THRESH_BINARY_INV);
 
        //track the possition of the ball
        trackObject(imgGrayScale);
 
        // Add the tracking image and the frame
        cvAdd(frame, imgTracking, frame);
 
        cvShowImage("Video", frame);
        cvShowImage("Videos", imgTracking);
        //Clean up used images
        cvReleaseImage(&imgGrayScale);
        cvReleaseImage(&frame);
 
        //Wait 10mS
        int c = cvWaitKey(10);
        //If 'ESC' is pressed, break the loop
        if ((char)c == 27) break;
    }
 
    cvDestroyAllWindows();
    cvReleaseImage(&imgTracking);
    cvReleaseCapture(&capture);
 
    return 0;
}
Mon second programme qui détecte le rouge

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <iostream>
#include <ctype.h>
#include <sstream>
#include "opencv\cv.h"
#include "opencv\highgui.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
 
 
//This function threshold the HSV image and create a binary image
IplImage* GetThresholdedImage(IplImage* imgHSV){
    IplImage* imgThresh = cvCreateImage(cvGetSize(imgHSV), IPL_DEPTH_8U, 1);
    cvInRangeS(imgHSV, cvScalar(129, 117, 62), cvScalar(180, 256, 256), imgThresh);
    return imgThresh;
}
 
int main(){
    CvCapture* capture = 0;
 
    capture = cvCaptureFromCAM(0);
    if (!capture){
        printf("Capture failure\n");
        return -1;
    }
 
    IplImage* frame = 0;
 
    cvNamedWindow("Video");
    cvNamedWindow("Ball");
 
 
    //iterate through each frames of the video     
    while (true){
 
        frame = cvQueryFrame(capture);
        if (!frame) break;
 
        frame = cvCloneImage(frame);
        cvSmooth(frame, frame, CV_GAUSSIAN, 3, 3); //smooth the original image using Gaussian kernel
 
        IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
        cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV
        IplImage* imgThresh = GetThresholdedImage(imgHSV);
 
        cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN, 3, 3); //smooth the binary image using Gaussian kernel
 
        cvShowImage("Ball", imgThresh);
        cvShowImage("Video", frame);
 
        //Clean up used images
        cvReleaseImage(&imgHSV);
        cvReleaseImage(&imgThresh);
        cvReleaseImage(&frame);
 
        //Wait 50mS
        int c = cvWaitKey(10);
        //If 'ESC' is pressed, break the loop
        if ((char)c == 27) break;
    }
 
    cvDestroyAllWindows();
    cvReleaseCapture(&capture);
 
    return 0;
}
Merci d'avance