xcodemacosopencvhighgui

cvCreateTrackbar() not working


i am building an app with openCV book for beginners. here is the code for the main.m file:

#include <iostream>
#include <opencv2/opencv.hpp>



 int g_slider_position = 0;
 CvCapture *g_capture = NULL;

 void onTrackBarSlide(int pos){
  cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
 }




 int main(int argc, const char * argv[])
 {
     cvNamedWindow("example3",CV_WINDOW_AUTOSIZE);
     g_capture =      cvCreateFileCapture("/Users/orazran/Desktop/android/sdk/extras/android/support/samples/Support     4Demos/res/raw/videoviewdemo.mp4");
     int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);

     printf("%d",frames);

     if (frames != 0) {
         cvCreateTrackbar("trackBar", "example3", &g_slider_position,frames,onTrackBarSlide);
     }

     IplImage *frame;
    while (1) {
    frame = cvQueryFrame(g_capture);
    if (!frame) break;

    cvShowImage("movieWindow", frame);
    char c = cvWaitKey(33);
    if (c == 27) break;

}
    cvReleaseCapture(&g_capture);
    cvDestroyWindow("movieWindow");
}

the movie is played well but i cant see the trackBar. what am i missing?


Solution

  • the problem was on my fault... the window identifier was set wrong. it should be "example3" instead of "movieWindow".