Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<highgui.h>
#include<cv.h>
#include<iostream>

int g_slider_position = 0;
CvCapture *g_capture = NULL;

void onTrackbarSlide(int position)
{
	cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, position);

	return;
}

int main()
{
	cvNamedWindow("sd", CV_WINDOW_AUTOSIZE);
	g_capture = cvCreateFileCapture("F://迅雷下载/永远的车神.rmvb");
	int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);
	if (frames != 0)
	{
		cvCreateTrackbar("position", "example", &g_slider_position, frames, onTrackbarSlide);
	}
	IplImage *frame;
	frame = cvQueryFrame(g_capture);
	while (frame)
	{
		cvShowImage("sd", frame);
		if (cvWaitKey(33) == 13)
			break;
		frame = cvQueryFrame(g_capture);
	}
	cvReleaseCapture(&g_capture);
	cvDestroyWindow("sd");
	std::cout << "Program end.\n";
	return 0;
}


What I have tried:

My program can run, and my code is almost same with my teaching book.
I just start to learn opencv, I can't find the problem.
Posted
Updated 26-Jul-17 21:49pm
v3

1 solution

If you read the documentation of cvCreateTrackbar you would know that you must the windows name to attach the trackbar.
C++
cvCreateTrackbar("position", "sd"/*your window name*/, &g_slider_position, frames, onTrackbarSlide);
should do the job.

Pretty easy :-O
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900