Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to call a function in a main function With OpenCv and C++?

Hi.I use below code for video capture from my webcam:

Mat frame;
int threshval =120;
static void on_trackbar(int, void*)
{


 }
 int main(int argc, char* argv[])
 {

     VideoCapture cap(0);
     if (!cap.isOpened())
     {
         cout << "Cannot open the video cam" << endl;
         return  0;

     }

     while (1)
     {
         bool bSuccess = cap.read(frame); // Khandane yek frame jadid dar video


         if (!bSuccess)
         {
             cout << "Cannot read a frame from video stream" << endl;
             break;
         }
    createTrackbar("Threshold", "Image", &threshval, 255, on_trackbar);
    on_trackbar(threshval, 0);}
             return 0; }

I want to use a function that takes the image from video capture class and convert that frame to a gray level image and use Canny Edge Detector for that image.for this reason I use this function:

int my_cannyEdgeDetector(){

         cvtColor(frame, frame2, COLOR_BGR2GRAY);
         Canny(frame2, frame2, threshval, threshval * 2, 3);}

I know I wrote the wrong function but I'm begginer in opencv and c++ and I want to get pictures from the main function and put it in the my_cannyEdgeDetector function and imshow frame and frame2 in the end of my main function.I have no idea to set input and output for my_cannyEdgeDetector function.Thank you very much if you help me do this