// need to return positive or negative
void initCaptureFiles( int argc, char *argv[], CvCapture **capture, CvCapture **stereoCapture, int *webcamRun, int *enable3D ) {
    if( argc < 3 ) {;
        printf("Incorrect arguments:\n");
        printf("Webcam: mainTracker mean.xml cov.xml\n");
        printf("2D video: mainTracker mean.xml cov.xml video.avi");
        printf("3D video: mainTracker mean.xml cov.xml video.avi stereo.avi\n");
        
        exit(1);
    }


    char locationVideoActual[300];
    char locationVideoStereo[300];
    
    if( argc == 3 ) {
        printf("Running on webcam\n");
        *webcamRun = 1;
    } else if( argc == 4 ) {
        strncpy( locationVideoActual, argv[3], 300 );
    } else if( argc == 5 ) {
        strncpy( locationVideoActual, argv[3], 300 );
        strncpy( locationVideoStereo, argv[4], 300 );
    } else {
        printf("Incorrect arguments:\n");
        printf("Webcam: mainTracker mean.xml cov.xml\n");
        printf("2D video: mainTracker mean.xml cov.xml video.avi");
        printf("3D video: mainTracker mean.xml cov.xml video.avi stereo.avi\n");
        
        exit(1);
    }
    
    
    if( *webcamRun ) {
        *capture       = cvCaptureFromCAM(0);
        *stereoCapture = cvCreateFileCapture( "nonexistantfile.avi" );
    } else {
        *capture       = cvCreateFileCapture( locationVideoActual );
        *stereoCapture = cvCreateFileCapture( locationVideoStereo );
    }
    
    if ( !*capture ) {
       fprintf( stderr, "Cannot open regular video file\n" );
       exit(1);
  } else {
       fprintf( stderr, "\nRegular video loaded ok\n" );
  }
  
  if ( *stereoCapture ) {
    printf("Depth file found, enabling 3D tracking\n");
    *enable3D = 1;
  } else {
    fprintf( stderr, "Could not open depth file, using 2D tracking" );
    *enable3D = 0;
  }
         
}
示例#2
0
void test() {
	CvCapture *capture = cvCreateFileCapture("D:\\²âÊÔÊÓƵ\\1344.avi");
	int frameWidth = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	int frameHeight = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
	codeBook *cb = new codeBook[frameWidth * frameHeight];
	memset(cb, 0, frameWidth * frameHeight * sizeof(codeBook));
	unsigned int bound[3] = { 10 ,10,10 };
	int minMod[3] = { 10 ,10,10 };
	int maxMod[3] = { 10 ,10,10 };
	IplImage *frame[1000];

	for (int i = 0; i < 1000; i++) {
		frame[i] = cvCreateImage(cvSize(frameWidth, frameHeight), 8, 3);
		cvCopy(cvQueryFrame(capture), frame[i]);
	}

	for (int i = 0; i < frameWidth * frameHeight; i++) {
		for (int j = 0; j < 1000; j++) {
			UpdateCodeBook((unsigned char*)frame[j]->imageData + i * 3, cb[i], bound, 3);
		}
	}

	IplImage *mask = cvCreateImage(cvSize(frameWidth, frameHeight), 8, 1);

	for (int i = 0; i < 1000; i++) {
		for (int j = 0; j < frameWidth * frameHeight; j++) {
			mask->imageData[j] = BackgroundDiff((unsigned char*)frame[i]->imageData + j * 3, cb[j], 3, minMod, maxMod);
		}
		FindConnectedComponents(mask);
		cvShowImage("1", mask);
		cvShowImage("2", frame[i]);
		cvWaitKey(30);
	}
}
示例#3
0
//Initialize capture from avi
int initVideoCapture(char* video_path)
{


	capture = cvCreateFileCapture(video_path);

	frames = (int) cvGetCaptureProperty(
		capture,
		CV_CAP_PROP_FRAME_COUNT
		);
  
// 	writer = cvCreateVideoWriter(
// 		"my_video.avi",
// 		CV_FOURCC('P','I','M','1'),
// 		30,
// 		size,
// 		isColor
// 		);

	printf("no of frames = %d", frames);

	if( !frames )
	{
		fprintf(stderr, "failed to initialize camera capture\n");
		return 0;
	}

	return 1;
}
//--------------------------------------------------------------------------------------
// Name: CVInit()
// Desc: Initializate OpenCV
//--------------------------------------------------------------------------------------
bool GLCVUtils::CVInit (int mode)
{
	if (mode == VIDEO_FILE)
	{
		capture = cvCreateFileCapture ("Ratatouille.avi");
		if (! capture) printf ("\n\n\nerror creating file capture\n\n\n");
			
	}
	
	else if (mode == CAMERA)
	{
		// create capture
		capture = cvCreateCameraCapture (0);
		if (! capture)
		{
			printf ("\nError creating capture");
			return false;
		}

		// sets camera (hardware) resolution
		cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH,  TEXTURE_W);
		cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, TEXTURE_H);
		
	}
	else
	{
		printf ("\nWrong Mode");
	}

	return true;
}
示例#5
0
int main(int argc, char* argv[]) {
	const char* filename = "./test.avi";
	if(argc > 1) {
		filename = argv[1];
	}

	CvCapture* cap = cvCreateFileCapture(filename);
	if(cap == NULL) {
		printf("open camera failed!\n");
		return -1;
	}
	cvSaveImage("video.jpg", cvQueryFrame(cap));

	const char* winName = "Go-OpenCV";
	cvNamedWindow(winName, 1);
	for(;;) {
		IplImage* img = cvQueryFrame(cap);
		cvShowImage(winName, img);
		if(cvWaitKey(50) == 27) {
			break;
		}
	}

	cvDestroyWindow(winName);
	cvReleaseCapture(&cap);
	return 0;
}
示例#6
0
int readVideoWithATrackbar(char *fileName)
{
	cvNamedWindow( "win_1", CV_WINDOW_AUTOSIZE );
	g_capture = cvCreateFileCapture( fileName );
	int frames = (int) cvGetCaptureProperty(
			g_capture,
			CV_CAP_PROP_FRAME_COUNT
			);
	if( frames != 0 ) {
		cvCreateTrackbar(
				"Position",
				"win_1",
				&g_slider_position,
				frames,
				onTrackbarSlide
				);
	}
	IplImage* frame;
	while (1) {
		frame = cvQueryFrame( g_capture );
		if ( !frame ) {
			break;
		}
		cvShowImage( "win_1", frame );
		char c = cvWaitKey(33);
		if ( c == 27 ) {
			break;
		}

	}
	return (0);
}
示例#7
0
int main(int argc, const char * argv[]) {
    CvCapture* capture = cvCreateFileCapture( argv[1] );
    if (!capture) return -1;
    
    IplImage* bgr_frame = cvQueryFrame( capture );
    double fps = cvGetCaptureProperty( capture ,  CV_CAP_PROP_FPS );
    CvSize size = cvSize(
        (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
        (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
    );
    CvVideoWriter* writer = cvCreateVideoWriter( argv[2], CV_FOURCC('M', 'J', 'P', 'G'), fps, size);
    IplImage* logpolar_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
    
    while ( (bgr_frame = cvQueryFrame(capture)) != NULL ) {
        cvLogPolar(bgr_frame, logpolar_frame,
                   cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
                   40,
                   CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
        cvWriteFrame(writer, logpolar_frame);
    }
    cvReleaseVideoWriter( &writer );
    cvReleaseImage( &logpolar_frame );
    cvReleaseCapture( &capture );
    return 0;
}
int main(int argc, char * const argv[])
{
	/* Initialize the camera */
	CvCapture *CamCapture = 0;
	CamCapture = cvCreateFileCapture("http://192.168.2.135:81/videostream.asf?user=viki&pwd=viki&resolution=640*480");
	if (!CamCapture)
	{printf("IP Cam not ready\n");
	return -1;}
	/* initialize video writer */
	CvVideoWriter *IPCamWriter = 0;
	CvSize size;
	size.width = 640;
	size.height = 480;
	IPCamWriter = cvCreateVideoWriter("/home/viki/Videos/IPCamOut.avi", CV_FOURCC('D','I','V','X'), 4, size, 1); //needs time index in naming

	/* time */
	time_t current_time;
	current_time = time (NULL);
	long int stop_time = current_time + 10;
	
	/* main loop */
	while( current_time < stop_time )
		{
		/* write image to file */
		cvWriteFrame(IPCamWriter, cvQueryFrame( CamCapture ));
		}
 
	/* Clean up memory */
	cvReleaseCapture ( &CamCapture );
	cvReleaseVideoWriter(&IPCamWriter);
}
示例#9
0
VideoCapture::VideoCapture(std::string _path_to_video,
						   int32_t _snapshot_delay) 
	: capture_frame(nullptr), frame(nullptr), path_to_video(_path_to_video), snapshot_delay(_snapshot_delay), window_name("Capture"), btv_sr(nullptr)
{
	capture_frame = cvCreateFileCapture(path_to_video.c_str());
	btv_sr = new NS_SuperResolution::SuperResolution();
}
示例#10
0
int main( int argc, char** argv ) { 
	
	if (argc == 1) {
		std::cout << "ERROR: missing filename" << std::endl;
		return -1;
		}
	
    cvNamedWindow( "Video Capture", CV_WINDOW_AUTOSIZE );
    
    //CvCapture* capture = cvCaptureFromAVI( argv[1] ); // either one will work
    
    CvCapture* capture = cvCreateFileCapture( argv[1] );

	if (capture == NULL) {
		std::cout << "ERROR: can not open file " << argv[1] << std::endl;
		return -1;
		}
    
    IplImage* frame;
    while(1) {
        frame = cvQueryFrame( capture );
        if( !frame ) break;
        cvShowImage( "Video Capture", frame );
        char c = cvWaitKey(33);
        if( c == 27 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Video Capture" );
}
示例#11
0
int main( int argc, char** argv ) {
	cvNamedWindow( "Example3", CV_WINDOW_AUTOSIZE );
	g_capture = cvCreateFileCapture( argv [1] );
	int frames = (int) cvGetCaptureProperty(
			g_capture,
			CV_CAP_PROP_FRAME_COUNT
		);
	if( frames!= 0 ) {
		cvCreateTrackbar(
			"Position",
			"Example3",
			&g_slider_position,
			frames,
			onTrackbarSlide
		);
	}
	IplImage* frame;
	while(1) {
		frame = cvQueryFrame( g_capture );
		if( !frame ) break;
		cvShowImage( "Example3", frame );
		char c = cvWaitKey(33);
		if( c == 27 ) break;
	}
	cvReleaseCapture( &g_capture );
	cvDestroyWindow( "Example3" );

	return(0);
}
示例#12
0
int main(int argc, char** argv){
	// Example2という名前のウィンドウを作成する
	cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
	// ビデオファイルからフレームを扱えるように準備する
	CvCapture *capture = cvCreateFileCapture(argv[1]);
	IplImage *frame;
	// ビデオファイルをループして表示する
	while(1){
		// ビデオファイルからフレームを読み出す
		frame = cvQueryFrame(capture);
		if(!frame){
			break;
		}
		// Example2のウィンドウにフレームを表示する
		cvShowImage("Example2", frame);
		// 33ミリ秒キー入力を待つ
		char c = cvWaitKey(33);
		// エスケープキーが押されればループを抜ける
		if(c == 27){
			break;
		}
	}
	// CvCapture変数を解放する
	cvReleaseCapture(&capture);
	// ウィンドウを閉じる
	cvDestroyWindow("Example2");
	return 0;
}
void THISCLASS::OnStart() {
	// Open file
	wxString filename_string = GetConfigurationString(wxT("File"), wxT(""));
	wxFileName filename = mCore->GetProjectFileName(filename_string);
	if (! filename.FileExists()) {
	  wxString msg = wxT("The avi file does not exist: ");
	  msg << filename_string;
	  AddError(msg);
	  return;
	}
	if (filename.IsOk()) {
	  mCapture = cvCreateFileCapture(filename.GetFullPath().mb_str(wxConvFile));
	}

	// Error? Check whether the file exists or not, to give an appropriate error message to the user
	if (mCapture == NULL) {
		std::fstream f;
		f.open(filename.GetFullPath().mb_str(wxConvFile));
		if (f.is_open()) {
			f.close();
			AddError(wxT("Can open the AVI file as a file, but not with OpenCV."));
			return;
		} else {
			AddError(wxT("Cannot open AVI file: permissions problem or something?"));
			return;
		}
	}

	// Reset to first frame
	cvSetCaptureProperty(mCapture, CV_CAP_PROP_POS_FRAMES, 0);
}
示例#14
0
void Kalman_Filter::video_extraction()
{
    cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
    CvCapture* capture = cvCreateFileCapture( "fi-br-m1.avi" );
    IplImage* frame;

    int frameNo = 0;

    while(1)
    {
        frame = cvQueryFrame( capture );

        if (frameNo == 0) cvSaveImage("model.png", frame, 0);

        if (frameNo == 30) cvSaveImage("data.png", frame, 0);

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

        frameNo++;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "video" );

}
示例#15
0
int main(int argc, char** argv) {
  CvCapture* capture = 0;
  IplImage* input = 0;
  IplImage* output = 0;
  int tick = 0, prev_tick = 0;
  double now = 0.0;
  CvFont font;
  char buffer[256];
  const char* windowName = "median";

  if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) {
    capture = cvCreateCameraCapture(argc == 2 ? argv[1][0] - '0' : 0);
  } else if (argc == 2) {
    capture = cvCreateFileCapture(argv[1]);
  }
  if (!capture) {
    fprintf(stderr, "ERROR: capture is NULL \n");
    return (-1);
  }

  cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
  cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0.0, 1, 0);
  input = cvQueryFrame(capture);
  if (!input) {
    fprintf(stderr, "Could not query frame...\n");
    return (-1);
  }
  output = cvCreateImage(cvSize(input->width, input->height), IPL_DEPTH_8U, 3);

  while (1) {
    input = cvQueryFrame(capture);
    if (!input) {
      fprintf(stderr, "Could not query frame...\n");
      break;
    }

    process(input, output);

    sprintf(buffer, "%3.1lfms", now / 1000);
    cvPutText(output, buffer, cvPoint(50, 150), &font, CV_RGB(255, 0, 0));

    cvShowImage(windowName, output);

    //If a certain key pressed
    if (cvWaitKey(10) >= 0) {
      break;
    }

    tick = cvGetTickCount();
    now = (tick - prev_tick) / cvGetTickFrequency();
    prev_tick = tick;
  }

  cvReleaseImage(&output);

  cvReleaseCapture(&capture);
  cvDestroyWindow(windowName);

  return 0;
}
示例#16
0
void the_project::project_init()
{
	car_of_pro = new the_car();


	//camera  480*640

	for_cam = cvCreateCameraCapture(1);
	for_video = cvCreateFileCapture("test.avi");
	image_size = cvSize(cvGetCaptureProperty(for_cam,3),cvGetCaptureProperty(for_cam,4));
	wr1 = cvCreateVideoWriter("record_ori.avi",CV_FOURCC('X','V','I','D') ,15,image_size);
	wr2 = cvCreateVideoWriter("record_cha.avi",CV_FOURCC('X','V','I','D') ,15,image_size);

	newpoints[0]=cvPoint2D32f(0,0);
	newpoints[1]=cvPoint2D32f(0,image_size.height);
	newpoints[2]=cvPoint2D32f(image_size.width,image_size.height);
	newpoints[3]=cvPoint2D32f(image_size.width,0);

	red_min=200;
	rg_max=100;
	rb_max=100;
	green_min=200;
	gb_max=100;
	gr_max=100;

}
示例#17
0
int main( int argc, char** argv ) {

    // CAPTURE VIDEO
    CvCapture* capture;
    capture = cvCreateFileCapture("trafficDay.avi");
    if( capture == NULL ) {
        fprintf (stderr, "cannot open file\n");
        exit(1);
    }


    // ALLOCATE SPACE FOR IplImage STRUCTURES.
    // DEFAULT ONE FROM VIDEO.
    IplImage *big_frame = cvQueryFrame(capture);
    IplImage *frame = cvCreateImage (cvSize(DEFAULT_SIZE(0), DEFAULT_SIZE(1)), big_frame->depth, big_frame->nChannels);
    IplImage *last_frame = cvCreateImage (cvSize(DEFAULT_SIZE(0), DEFAULT_SIZE(1)), big_frame->depth, big_frame->nChannels);
    IplImage *diff = cvCreateImage (cvSize(DEFAULT_SIZE(0), DEFAULT_SIZE(1)), big_frame->depth, big_frame->nChannels);
    cvResize (big_frame, last_frame, CV_INTER_LINEAR );


    // CREATE WINDOWS AND LOCATE THEM TO TOP LEFT OF THE SCREEN
    cvNamedWindow( "Video", CV_WINDOW_AUTOSIZE);
    cvNamedWindow( "Difference", CV_WINDOW_AUTOSIZE);
    cvMoveWindow ("Video", 100, 0);
    cvMoveWindow ("Difference", 100, 500);


    // MAIN LOOP
    while((big_frame = cvQueryFrame (capture)) != NULL) {
        // RESIZE IMAGE FROM VIDEO
        cvResize (big_frame, frame, CV_INTER_LINEAR );
        // SHOW CAPTURED AND RESIZED IMAGE
        cvShowImage("Video", frame);

        // COMPUTE AND SWOW DIFFERENCE
        cvSub (frame, last_frame, diff, NULL);
        cvShowImage("Difference", diff);

        // WAIT FOR BREAK AND TO ADJUST FPS
        char c = cvWaitKey(50);
        if(c == 27) break;

        // UPDATE LAST FRAME
        cvCopy (frame, last_frame, NULL);

    }

    //RELEASE IMAGE STRUCTURES
    cvReleaseImage (&last_frame);
    cvReleaseImage (&frame);
    cvReleaseImage (&diff);

    // RELEASE CAPTURE
    cvReleaseCapture(&capture);
    // DESTROY WINDOWS
    cvDestroyWindow("Video");
    cvDestroyWindow("Difference");
    return 0;
}
//----------------------------------------------------------------------------------------------------
BOOL CMyVideoOpenCV::CaptureVideoFile(CString szFileName)
{
	SetVideoType(VIDEO_FILE);
	SetFileName(szFileName);
	
	m_pCapture = cvCreateFileCapture(szFileName);
	if(!m_pCapture) return FALSE;

	return TRUE;
}
示例#19
0
bool VideoCapture::open(const String& filename)
{
    if (isOpened()) release();
    icap = IVideoCapture_create(filename);
    if (!icap.empty())
        return true;

    cap.reset(cvCreateFileCapture(filename.c_str()));
    return isOpened();
}
示例#20
0
void FaceDetect::detectVideo(const char* videoFile) {
  CvCapture* capture = cvCreateFileCapture(videoFile);
  cv::Mat frame;
  while(true) {
    frame = cvQueryFrame(capture);
    if(frame.empty())
      break;
    detect(frame);
  }
}
示例#21
0
CvCapture* ipGetCapture(char* Filename)
{
	CvCapture* capture = cvCreateFileCapture(Filename);
	if( !capture ) 
	{
        fprintf( stderr, "ERROR: capture is NULL \n" ); 
		//return -1;
    }
	return capture;
}
示例#22
0
mvCamera:: mvCamera (const char* video_file) :
    bin_resize ("mvCamera - resize"),
    bin_getFrame ("mvCamera - getFrame")
{
    unsigned width, height;
    read_common_mv_setting ("IMG_WIDTH_COMMON", width);
    read_common_mv_setting ("IMG_HEIGHT_COMMON", height);
    
    _capture = cvCreateFileCapture (video_file);   
    _imgResized = mvGetScratchImage_Color();
}
示例#23
0
Camera::Camera(const char* filename,
		const char* homographyFile,
		const char* inverseFile)
{
    if((capture = cvCreateFileCapture(filename)) == NULL)
    {
        printf("Error creating file capture for file %s\n", filename);
    }
	loadHomography(homographyFile, inverseFile);
	getCameraProperties();
}
示例#24
0
//------------------------------------------------------------------------------
void OgreVideoTexture::_initCapture()
{
    
    mCvCapture = cvCreateFileCapture(mVideoFileName.c_str());
    mFrameCount = cvGetCaptureProperty(mCvCapture, CV_CAP_PROP_FRAME_COUNT);

    // skip first frame
    cvGrabFrame(mCvCapture);
    mCurrentFrameIndex++;

    _logMessage("openned " + mVideoFileName);
}
示例#25
0
/** Permet de choisir le fichier à lire, et déclenche la lecture */
void Ui_MainWindow::select_file(){
  QString filename = QFileDialog::getOpenFileName(this,tr("OpenImage"), "/home");
  if (filename != NULL) {
    killTimer(timer_id);
    QByteArray filename_array = filename.toLatin1();
    const char* filename_string = filename_array.data();
    source = cvCreateFileCapture(filename_string);
    assert(source);
    timer_id = startTimer(1);
  }
  return;
}
示例#26
0
int main( int argc, char** argv )
{
	int frameNum = 0;

    printf("Debug 00\n");
	char* video = argv[1];
    printf("Debug 11 %s \n",argv[1]);
	capture = cvCreateFileCapture(video);

	if( !capture ) { 
		printf( "Could not initialize capturing..\n" );
		return -1;
	}
	
	if( show == 1 )
		cvNamedWindow( "Video", 0 );

	while( true ) {
		IplImage* frame = 0;
		int i, j, c;

		// get a new frame
		frame = cvQueryFrame( capture );
		if( !frame ) {
			printf("debug 0");
			break;
		}

		if( !image ) {
			printf("debug 1");
			image =  cvCreateImage( cvSize(frame->width,frame->height), 8, 3 );
			image->origin = frame->origin;
		}

		cvCopy( frame, image, 0 );

		if( show == 1 ) {
			printf("debug 2");
			cvShowImage( "Video", image);
			c = cvWaitKey(3);
			if((char)c == 27) break;
		}
		
		std::cerr << "The " << frameNum << "-th frame" << std::endl;
		frameNum++;
	}

	if( show == 1 )
		cvDestroyWindow("Video");

	return 0;
}
示例#27
0
int main( int argc, char** argv){

    IplImage  *frame;
    int       key;

    /* supply the AVI file to play */
    assert( argc == 2 );

    /* load the AVI file */
    CvCapture *capture = cvCreateFileCapture(argv[1]) ; //cvCaptureFromAVI( argv[1] );

    /* always check */
    if( !capture ) {
        printf("ERROR: capture == NULL \n");
        return 1;    
    }

    /* get fps, needed to set the delay */
    int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );

    int frameH    = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
    int frameW    = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);

    /* display video */
    cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );

    while( key != 'q' ) {

    double t1=(double)cvGetTickCount();
    /* get a frame */
    frame = cvQueryFrame( capture );
    double t2=(double)cvGetTickCount();
    printf("time: %gms  fps: %.2g\n",(t2-t1)/(cvGetTickFrequency()*1000.), 1000./((t2-t1)/(cvGetTickFrequency()*1000.)));

    /* always check */
    if( !frame ) break;

    /* display frame */
    cvShowImage( "video", frame );

    /* quit if user press 'q' */
    key = cvWaitKey( 1000 / fps );
    }

    /* free memory */
    cvReleaseCapture( &capture );
    cvDestroyWindow( "video" );

    return 0;
}
示例#28
0
static int l_initCam(lua_State *L) {
  // args
  int width = lua_tonumber(L, 2);
  int height = lua_tonumber(L, 3);

  // max allocs ?
  if (fidx == MAXIDX) {
    perror("max nb of devices reached...\n");
  }

  // if number, open a camera device
  if (lua_isnumber(L, 1)) {
    printf("initializing camera\n");
    const int idx = lua_tonumber(L, 1);
    capture[fidx] = cvCaptureFromCAM(idx);
    if( capture[fidx] == NULL ) {
      perror("could not create OpenCV capture");
    }
    //    sleep(2);
    //cvSetCaptureProperty(capture[fidx], CV_CAP_PROP_FRAME_WIDTH, width);
    //cvSetCaptureProperty(capture[fidx], CV_CAP_PROP_FRAME_HEIGHT, height);
    frame[fidx] = cvQueryFrame ( capture[fidx] );
    int tries = 10;
    while ((!frame[fidx] || frame[fidx]->height != height || frame[fidx]->width != width) && tries>0) {
      frame[fidx] = cvQueryFrame ( capture[fidx] );
      tries--;
      sleep(1);
    }
    if ( frame[fidx] == NULL ) {
      perror("failed OpenCV test capture");
    }
    if(frame[fidx]->depth != IPL_DEPTH_8U) {
      perror("initCam: opencv supported for 8-bit unsigned capture only");
    }
    printf("camera initialized\n");
  } else {
    // open a file;
    const char *file = lua_tostring(L, 1);
    printf("initializing frame grabber on file: %s\n", file);
    capture[fidx] = cvCreateFileCapture(file);
    if( capture[fidx] == NULL ) {
      perror("could not create OpenCV capture");
    }
  }

  // next
  lua_pushnumber(L, fidx);
  fidx ++;
  return 0;
}
示例#29
0
int main( int argc, char* argv[] ) {

    CvCapture* capture = NULL;
    if (argc >= 2) {
      capture = cvCreateFileCapture( argv[1] );
    } else {
      capture = cvCreateCameraCapture( 0 );
    }

    cvNamedWindow( "Original", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "Grayscale", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "Canny edge detection", CV_WINDOW_AUTOSIZE );

    IplImage* frame = NULL;
    IplImage* frame_gray = NULL;
    IplImage* frame_edges = NULL;
    while (1) {

        frame = cvQueryFrame(capture);
        if (!frame) break;

        cvShowImage( "Original", frame );

        // Turn to grayscale;
        frame_gray = cvCreateImage( cvGetSize(frame), frame->depth, 1 );
        cvCvtColor(frame, frame_gray, CV_RGB2GRAY);
        cvSmooth( frame_gray, frame_gray, CV_GAUSSIAN, 5); // TODO: is this really necessary???
        cvShowImage( "Grayscale", frame_gray );

        // Perform Canny edge detection;
        frame_edges = cvCreateImage( cvGetSize(frame), frame->depth, 1 );
        cvCanny( frame_gray, frame_edges, 10, 100, 3 );
        cvShowImage( "Canny edge detection", frame_edges );

        char c = cvWaitKey(33);
        if ( c == 27 ) break;

    }

    cvReleaseImage( &frame );
    cvReleaseImage( &frame_gray );
    cvReleaseImage( &frame_edges );
    cvReleaseCapture( &capture );
    cvDestroyWindow( "Original" );
    cvDestroyWindow( "Grayscale" );
    cvDestroyWindow( "Canny edge detection" );

    return 0;

}
示例#30
0
int main( int argc, char** argv ) {

	// create a window with appropriate size. Windows name is determined by file name
	// supplied as an argument
	cvNamedWindow( argv[1], CV_WINDOW_AUTOSIZE );
	// open video
	g_capture = cvCreateFileCapture( argv[1] );
	// set read position in units of frames and retrieve total number of frames
	int frames = (int) cvGetCaptureProperty(
		g_capture,
		CV_CAP_PROP_FRAME_COUNT
	);


	// do not create treackbar if video does not include an information
	// about number of frames
	if( frames!=0 ) {

	cvCreateTrackbar(
		"Position",
		argv[1],
		&g_slider_position,
		frames,

		onTrackbarSlide
	);
	}

	// display video frame by frame
	IplImage* frame;
	while(1) {

		frame = cvQueryFrame( g_capture );
		if( !frame ) break;
		cvShowImage( argv[1], frame );
		// set trackbar to a current frame position
		cvSetTrackbarPos("Position", argv[1], g_slider_position);

		g_slider_position++;

		char c = cvWaitKey(33);
		// quit if ESC is pressed
		if( c == 27 ) break;

		}
	// free memory
	cvReleaseCapture( &g_capture );
	cvDestroyWindow( argv[1] );
	return(0);
}