我正在为初学者构建一个带openCV书籍的应用程序。这是main.m
文件的代码:
#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");
}
电影播放效果不错但我看不到trackBar。 我错过了什么?
答案 0 :(得分:1)
问题出在我的错上......窗口标识符设置错误。它应该是“example3”而不是“movieWindow”。