Exemplo n.º 1
0
//------------------------------------------------------------------------------
void OgreVideoTexture::_createTextureFromCapture(CvCapture *_capture)
{

    int w, h;
    w = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
    h = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);

    Ogre::TextureManager *TM = Ogre::TextureManager::getSingletonPtr();

    // Create the texture
    mVideoTexture = Ogre::TextureManager::getSingleton().createManual(
        mTextureName, // name
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D,      // type
        1024, 1024,         // width & height
        0,                // number of mipmaps
        Ogre::PF_BYTE_BGR,
        Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    _initTexture(mVideoTexture);

    // Create a material using the texture
    mVideoMaterial = Ogre::MaterialManager::getSingleton().create(
        mMaterialName, // name
        Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    mVideoMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mTextureName);
    //mVideoMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);

}
Exemplo n.º 2
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;
}
void trainBackgroundModel(CvCapture* capture)
{
	CvSize frame_size;
	frame_size.height = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT );
	frame_size.width = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );

	if(background_model != NULL)
		delete background_model;
	background_model = new pixel_data*[frame_size.height];
	for(int i = 0; i < frame_size.height; i++)
		background_model[i] = new pixel_data[frame_size.width];

	const char* title = "Training Background Model";
	std::vector<const char*> lines;

	for(int i = 5; i >= 0; i--)
	{
		char buffer[400];
		sprintf(buffer, "Starting training in %d ...", i);
		lines.clear();
		lines.push_back(buffer);

		setOptions(title, lines);
		cvWaitKey(1000);
	}

	for(int num_frames = 0; num_frames < NUM_BACKGROUND_TRAINING_FRAMES; num_frames++)
	{
        
		char buffer[400];
		sprintf(buffer, "%g%%", ((double)num_frames/NUM_BACKGROUND_TRAINING_FRAMES*100.0));
		lines.clear();
		lines.push_back(buffer);
		setOptions(title, lines);

		/* get a frame */
		IplImage* frame = cvQueryFrame( capture );

		RgbImage img(frame);
		for(int i = 0; i < frame->height; i++)
		{
			for(int j = 0; j < frame->width; j++)
			{
				background_model[i][j].addDataPoint(img[i][j].r, img[i][j].g, img[i][j].b);
			}
		}
 
		/* always check */
		if( !frame ) break;

		cvShowImage(MAIN_WINDOW, frame);
		
		cvWaitKey(10);
    }


	lines.push_back("Done");
	setOptions(title, lines);
	cvWaitKey(3000);
}
Exemplo n.º 4
0
void Init(int argc, char *argv[])
{  
  capture = cvCaptureFromCAM(CV_CAP_ANY);
  if(!capture){
    std::cout << "error starting video capture" << std::endl;
    exit(0);
  }
  //propose a resolution
  cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);
  cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);
  //get the actual (supported) resolution
  ivWidth = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
  ivHeight = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
  std::cout << "camera/video resolution: " << ivWidth << "x" << ivHeight << std::endl;
  #ifdef FORCE_RESIZING
  ivWidth = RESOLUTION_X;
  ivHeight = RESOLUTION_Y;
  #endif
  
  cvNamedWindow("MOCTLD", 0); //CV_WINDOW_AUTOSIZE );
  
  CvSize wsize = {ivWidth, ivHeight};
  curImage = cvCreateImage(wsize, IPL_DEPTH_8U, 3);
  
  cvResizeWindow("MOCTLD", ivWidth, ivHeight);
  cvSetMouseCallback("MOCTLD", MouseHandler);
}
Exemplo n.º 5
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;

}
Exemplo n.º 6
0
//void StereoDisplay::SetFileName(LPSTR filename)
bool StereoDisplay::SetFileName(void)
{
     int isColor = 1;
     double fps = cvGetCaptureProperty( camera0_->capture_, CV_CAP_PROP_FPS);
     CvSize size = cvSize( (int)cvGetCaptureProperty( camera0_->capture_, CV_CAP_PROP_FRAME_WIDTH),
                           (int)cvGetCaptureProperty( camera0_->capture_, CV_CAP_PROP_FRAME_HEIGHT));
                           //http://www.xvidmovies.com/codec/ 
                           // divx.com
     //writer_ = cvCreateVideoWriter( filename, CV_FOURCC_DEFAULT, fps, size, isColor );                // XP Codec Pack 2.5.1
     //writer_ = cvCreateVideoWriter( filename, CV_FOURCC('X','V','I','D'), fps, size );                // XP Codec Pack 2.5.1
     //writer_ = cvCreateVideoWriter( "mytest.divx", CV_FOURCC('D','I','V','X'), fps, size );                // XP Codec Pack 2.5.1
     //writer_ = cvCreateVideoWriter( file_name, CV_FOURCC('U','2','6','3'), fps, size );                // XP Codec Pack 2.5.1
     //writer_ = cvCreateVideoWriter( file_name, CV_FOURCC('D','I','V','3'), fps, size );                // XP Codec Pack 2.5.1
     writer_ = cvCreateVideoWriter( "flv1.avi", CV_FOURCC('F','L','V','1'), fps, size );                // XP Codec Pack 2.5.1  
     if( NULL == writer_ )
     {
       return false;
     }      
     else
     {   
       logpolarframe_ = cvCreateImage(size, IPL_DEPTH_8U,3);
       recording_ = true;
       return true;
     }
     
}
Exemplo n.º 7
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);
	}
}
Exemplo n.º 8
0
void Video_to_image(char* filename)
{
printf("------------- video to image ... ----------------\n");
//初始化一个视频文件捕捉器
CvCapture* capture = cvCaptureFromAVI(filename);
//获取视频信息
cvQueryFrame(capture);
int frameH    = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
int frameW    = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int fps       = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
printf("\tvideo height : %d\n\tvideo width : %d\n\tfps : %d\n\tframe numbers : %d\n", frameH, frameW, fps, numFrames);
//定义和初始化变量
int i = 0;
IplImage* img = 0;
char image_name[13];

cvNamedWindow( "mainWin", CV_WINDOW_AUTOSIZE );
//读取和显示
while(1)
{
  
   img = cvQueryFrame(capture); //获取一帧图片
   cvShowImage( "mainWin", img ); //将其显示
   char key = cvWaitKey(20);
  
   //sprintf(image_name, "%s%d%s", "image", ++i, ".jpg");//保存的图片名
  sprintf(image_name, "%s%d%s", "", ++i, ".jpg");//保存的图片名
   cvSaveImage( image_name, img);   //保存一帧图片

   if(i == NUM_FRAME) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("mainWin");
}
Exemplo n.º 9
0
void MyVideo::loadResource(char* folder) {
    //search the folder for images and video
    DIR *dir = NULL;
    dirent *ent = NULL;

    dir = opendir(folder);

    //if the folder is invalid
    if (dir == NULL) {
        cout<<"Invalid folder"<<endl;
        return;
    }

    //get all the files
    while ((ent = readdir(dir)) != NULL) {
        //find the first '.'
        char* suffix = (char*)malloc(sizeof(char));
        sscanf(ent->d_name, "%*[^.]%s", suffix);
        char* input_src = (char*)malloc(sizeof(char));
        strcpy(input_src, folder);
        strcat(input_src, ent->d_name);
        if((strcmp(suffix, ".avi") == 0)&&(ent->d_name[0]!='.')) {
            inputvideo = cvCaptureFromFile(input_src);
        }
        if((strcmp(suffix, ".jpg") == 0)&&(ent->d_name[0]!='.')) {
            IplImage *p = cvLoadImage(input_src, 1);
            images.push_back(p);
        }
    }
    width = (int)cvGetCaptureProperty(inputvideo, 3);
    height = (int)cvGetCaptureProperty(inputvideo, 4);
    fps = (int)cvGetCaptureProperty(inputvideo, 5);
    fourcc = (int)cvGetCaptureProperty(inputvideo, 6);
    framecount = (int)cvGetCaptureProperty(inputvideo, 7);
}
Exemplo n.º 10
0
int StereoCamera::setup(CvSize imageSize){
    this->imageSize = imageSize;

    //captures[0] = cvCaptureFromCAM(CV_CAP_DSHOW + 0);
    //captures[1] = cvCaptureFromCAM(CV_CAP_DSHOW + 1);

    captures[0] = cvCaptureFromCAM(CV_CAP_ANY + 0);
    captures[1] = cvCaptureFromCAM(CV_CAP_ANY + 1);

    if(captures[0] == NULL)
    {
        printf("error\n");
    }

    if( captures[0] && captures[1]){

        for(int i=0;i<2;i++){
                cvSetCaptureProperty(captures[i], CV_CAP_PROP_FRAME_WIDTH, imageSize.width);
                cvSetCaptureProperty(captures[i], CV_CAP_PROP_FRAME_HEIGHT, imageSize.height);
        }

        printf("%d\n", (int)cvGetCaptureProperty(captures[0], CV_CAP_PROP_FRAME_WIDTH));
        printf("%d\n", (int)cvGetCaptureProperty(captures[0], CV_CAP_PROP_FRAME_HEIGHT));

        ready = true;
        return RESULT_OK;
    }else{
        ready = false;
        return RESULT_FAIL;
    }

}
Exemplo n.º 11
0
// Get the resolutions of a device
void Cam::getDeviceInfo(int d){
    CvCapture *cap = cvCreateCameraCapture(d);
    num_resolutions = 0;

    for(int i=0; i<N_RESOLUTIONS; i++){
        // Set actual values of resolution
        cvSetCaptureProperty( cap, CV_CAP_PROP_FRAME_WIDTH, c_resolutions[i].x );
        cvSetCaptureProperty( cap, CV_CAP_PROP_FRAME_HEIGHT, c_resolutions[i].y );

        // Compare the actual resolution value with the last accepted value (Width and Height)
        if( c_resolutions[i].x == cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH)
            && c_resolutions[i].y == cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT) ){
            resolutions[num_resolutions].x = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH);
            resolutions[num_resolutions].y = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT);
            num_resolutions++;
        }

    }
    cvReleaseCapture(&cap);

    /*
    for(int i=0; i<num_resolutions; i++){
        std::cout << i << ": " << resolutions[i].x << ", " << resolutions[i].y << std::endl;
    }
    */
}
Exemplo n.º 12
0
int
main (int argc, char **argv)
{
  CvCapture *capture = 0;
  IplImage *frame = 0;
  CvVideoWriter *writer;
  int c, num = 0;
  //CvFont font;
  //char str[64];

  double fps, width, height;
  if ( argc == 1 || (argc >= 2 && strlen (argv[1]) == 1 && isdigit (argv[1][0])) )
  {
    capture = cvCreateCameraCapture (argc == 2 ? argv[1][0] - '0' : 0);
    fps     = 20.0;
    width   = 320;
    height  = 240;
    //fps     = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_WIDTH, width);
    //cvSetCaptureProperty (capture, CV_CAP_PROP_FRAME_HEIGHT, height);
  }
  else if ( argc >= 2 )
  {
    capture = cvCaptureFromFile(argv[1]);
    fps     = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    width   = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    height  = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
  }
  printf ("fps=%f width=%f height=%f\n", fps, width, height);

  printf ("Write to cap.avi. Finish with Esc.\n");
  // FourCC http://www.fourcc.org/codecs.php
  //writer = cvCreateVideoWriter( "cap.avi", 
  //                              CV_FOURCC('D','I','V','X'),
  //                              fps, cvSize((int)width,(int)height) );
  writer = cvCreateVideoWriter( "cap.avi", -1,
      fps, cvSize((int)width,(int)height) );

  //cvInitFont (&font, CV_FONT_HERSHEY_COMPLEX, 0.7, 0.7);
  cvNamedWindow ("Capture", CV_WINDOW_AUTOSIZE);

  while (1) {
    frame = cvQueryFrame (capture);
    if( frame == NULL ) break;
    //snprintf (str, 64, "%03d[frame]", num);
    //cvPutText (frame, str, cvPoint (10, 20), &font, CV_RGB (0, 255, 100));
    cvWriteFrame (writer, frame);
    cvShowImage ("Capture", frame);
    num++;
    c = cvWaitKey (10);
    if (c == 'q') // exit
      break;
  }
  cvReleaseVideoWriter (&writer);
  cvReleaseCapture (&capture);
  cvDestroyWindow ("Capture");

  return 0;
}
Exemplo n.º 13
0
Arquivo: vid.c Projeto: lecram/ipg
int
main(int argc, char *argv[])
{
    CvCapture *capture = NULL;
    IplImage *src_frame, *image, *dst_frame;
    char *infile, *outfile;
    Matrix matrix;
    Args args;
    int64 t0, t1;
    double tps, deltatime;
    CvVideoWriter *writer;
    CvSize size;
    double fps;
    int frame_count;
    int i;

    infile = argv[1];
    outfile = argv[2];
    args.c = argc - 3;
    for (i = 0; i < 3; i++)
        args.v[i] = argv[i + 3];
    capture = cvCaptureFromFile(infile);
    if (capture == NULL) {
        printf("Could not load video \"%s\".\n", infile);
        return EXIT_FAILURE;
    }
    src_frame = cvQueryFrame(capture);
    fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
    size = cvSize(
        (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
        (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
    );
    writer = cvCreateVideoWriter(outfile, CV_FOURCC('M', 'J', 'P', 'G'), fps, size, 1);
    printf("Saving to \"%s\"...\n", outfile);
    image = cvCreateImage(size, IPL_DEPTH_8U, 1);
    dst_frame = cvCreateImage(size, IPL_DEPTH_8U, 3);
    matrix.width = dst_frame->width;
    matrix.height = dst_frame->height;
    frame_count = 0;
    t0 = cvGetTickCount();
    while ((src_frame = cvQueryFrame(capture)) != NULL) {
        cvCvtColor(src_frame, image, CV_BGR2GRAY);
        matrix.data = (unsigned char *) image->imageData;
        proc(&matrix, &args);
        cvCvtColor(image, dst_frame, CV_GRAY2BGR);
        cvWriteFrame(writer, dst_frame);
        frame_count++;
    }
    t1 = cvGetTickCount();
    tps = cvGetTickFrequency() * 1.0e6;
    deltatime = (double) (t1 - t0) / tps;
    printf("%d frames of %dx%d processed in %.3f seconds.\n",
           frame_count, dst_frame->width, dst_frame->height,
           deltatime);
    cvReleaseVideoWriter(&writer);
    cvReleaseImage(&dst_frame);
    cvReleaseCapture(&capture);
    return EXIT_SUCCESS;
}
Exemplo n.º 14
0
int main(int argc, char* argv[])
{
        // получаем любую подключённую камеру
        CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 );
        assert( capture );

        //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640);//1280); 
        //cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480);//960); 

        // узнаем ширину и высоту кадра
        double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
        double height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
        printf("[i] %.0f x %.0f\n", width, height );

        IplImage* frame=0;

        cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);

        printf("[i] press Enter for capture image and Esc for quit!\n\n");

        int counter=0;
        char filename[512];

        char text_buf[32];
        CvFont myFont;
//        cvInitFont(&myFont, СV_FONT_HERSHEY_PLAIN, 0.7, 1, 0, 1, 8);
        cvInitFont(&myFont, CV_FONT_HERSHEY_PLAIN, 2, 1, 0, 1, 8);

        while(true){
                // получаем кадр
                frame = cvQueryFrame( capture );

                //Filters
                cvtColor(frame, pic, CV_BGR2HSV);
                GaussianBlur(pic, pic, Size(7,7), 1.5, 1.5);

                sprintf(text_buf,"Hello!!!");
                cvPutText(frame, text_buf, cvPoint(5,15), &myFont, cvScalar(0,0,255));

                // показываем
                cvShowImage("capture", frame);
        
                char c = cvWaitKey(33);
                if (c == 27) { // нажата ESC
                        break;
                }
                else if(c == 13) { // Enter
                        // сохраняем кадр в файл
                        sprintf(filename, "Image%d.jpg", counter);
                        printf("[i] capture... %s\n", filename);
                        cvSaveImage(filename, frame);
                        counter++;
                }
        }
        // освобождаем ресурсы
        cvReleaseCapture( &capture );
        cvDestroyWindow("capture");
        return 0;
}
Exemplo n.º 15
0
CvSize getCaptureSize(CvCapture *capture)
{
    CvSize sz;
	sz.width = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	sz.height = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
    LOGD("capture size: %dx%d", sz.width, sz.height);
	return sz;
}
Exemplo n.º 16
0
Video::Video(const char *addr)
{
	capture = cvCaptureFromAVI(addr);
	height    = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
	width     = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	fps       = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
	numFrames = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_COUNT);
}
Exemplo n.º 17
0
int imAcqVidGetNumberOfFrames(ImAcq *imAcq)
{
    fprintf(stderr," %d <---\n",cvGetCaptureProperty(imAcq->capture , CV_CAP_PROP_FRAME_COUNT));
    fprintf(stderr," %d <---\n",(int)cvGetCaptureProperty(imAcq->capture , CV_CAP_PROP_FRAME_COUNT));
    fprintf(stderr," %d <---\n",(int)getAVIFrames(imAcq->imgPath));
    // return ((int) cvGetCaptureProperty(imAcq->capture , CV_CAP_PROP_FRAME_COUNT));
     return getAVIFrames(imAcq->imgPath);

}
Exemplo n.º 18
0
void Ibex::VLCVideoPlayer::initOpenCV(bool isStereo, int cameraId) {
  if(!openCVInited) {
    captureVideo = true;
    cvCapture = cvCaptureFromCAM(cameraId);//cvCreateCameraCapture(cameraId);
    width = cvGetCaptureProperty(cvCapture, CV_CAP_PROP_FRAME_WIDTH);
    height = cvGetCaptureProperty(cvCapture, CV_CAP_PROP_FRAME_HEIGHT);
    createVideoTextures(isStereo, width, height);
    openCVInited = true;
  }
}
Exemplo n.º 19
0
int Camera_init()
{
        capture = cvCaptureFromCAM(-1);
        assert( capture != NULL );
        int width = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );
        int height = (int) cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT);
        pixels_per_frame = width*height;
       	
        return 0;
}
Exemplo n.º 20
0
void *record_main(void *data)
{
    RecWindow *window = (RecWindow*)data;

    IplImage *imagesrc = cvQueryFrame(window->capture);//Init the video read
    double fps = 30;
    CvSize size = cvSize((int)cvGetCaptureProperty( window->capture, CV_CAP_PROP_FRAME_WIDTH),
                         (int)cvGetCaptureProperty( window->capture, CV_CAP_PROP_FRAME_HEIGHT));
    CvVideoWriter *writer = cvCreateVideoWriter(TEMP_VIDEO_ADDRESS, CV_FOURCC('M','P','E','G'), fps, size );

    int i = 0;
    timeval time_start,time_now;
    gettimeofday(&time_start,NULL);
    i = gettimeofday(&time_now,NULL);
    while (true)
    {
        i++;
        imagesrc = cvQueryFrame( window->capture );
        if (window->a_preview->isChecked()) //slow mode
        {
            if (imagesrc == NULL)
            {
                window->imageView = QImage((const unsigned char*)(window->NA_image->imageData), window->NA_image->width,window->NA_image->height,QImage::Format_RGB888).rgbSwapped();
                window->surface->setPixmap(QPixmap::fromImage(window->imageView.scaled(window->surface_width,
                                           floor((window->surface_width/window->NA_image->width)*window->NA_image->height),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
                return NULL;
            }
            window->imageView = QImage((const unsigned char*)(imagesrc->imageData), imagesrc->width,imagesrc->height,QImage::Format_RGB888).rgbSwapped();
            window->surface->setPixmap(QPixmap::fromImage(window->imageView.scaled(window->surface_width,
                                       floor((window->surface_width/imagesrc->width)*imagesrc->height),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));


        }
        cvWriteFrame( writer, imagesrc );
        if (gettimeofday( &time_now , NULL ) < 0)
        {
            printf("Error in getting time");
            return NULL;
        }
        //update info
        window->info_frameNum->setText(QString("Farme = %1").arg(i));
        window->info_time->setText(QString("Time : 0:%1:%2").arg((int)(time_now.tv_sec) - (int)(time_start.tv_sec)).arg((int)(time_now.tv_usec/100000)));
        int elapsed = ((int)(time_now.tv_sec) - (int)(time_start.tv_sec));
        if (elapsed)
            window->info_fps->setText(QString("RPS = %1").arg(i/elapsed));

        if (!window->isRec)
        {
            break;
        }
    }
    cvReleaseVideoWriter( &writer );
    return NULL;
}
Exemplo n.º 21
0
IplImage * VideoBackground::GetBackground()
{
	int current = cvGetCaptureProperty(m_capture, CV_CAP_PROP_POS_FRAMES);
	int last = cvGetCaptureProperty(m_capture, CV_CAP_PROP_FRAME_COUNT);
	if(current == last) 
	{
		cvReleaseCapture(&m_capture);
		m_capture = cvCaptureFromFile(m_filename.c_str());
	}
	return cvQueryFrame(m_capture);
}
Exemplo n.º 22
0
CameraGrabber::CameraGrabber()
:capture(0), width(0), height(0), framerate(30)
{
	capture = cvCaptureFromCAM(CV_CAP_ANY);
        if(capture)
        {
            width = (u32)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
            height = (u32)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
            framerate = (f32)cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
        }
}
Exemplo n.º 23
0
void Camera::setSize(int w, int h)
{
	// TODO: The following doesn't seem to work. OpenCV build issue?
	// XXX: I hacked DEFAULT_V4L_WIDTH/HEIGHT in highgui/cvcap_v4l.cpp as a 
	// temporary fix for this problem. Video4Linux definitely needs patching.
	cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, (double)w);
	cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, (double)h);

	width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
}
Exemplo n.º 24
0
Arquivo: utils.c Projeto: o2co2/ASEF
void get_camera_properties(CvCapture * capture, int *frame_width, int *frame_height, double *fps){
  	if ( !capture ) return ;
	if ( frame_width ){
		*frame_width = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	}
	if ( frame_height ){
		*frame_height = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
	}
	if ( fps ){
		*fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
	}
}
Exemplo n.º 25
0
void AVIReader::open() {
	if (videoCap)
		cvReleaseCapture(&videoCap);
	videoCap = cvCaptureFromFile(filePath.c_str());
	if (!videoCap)
		repErr("Cannot open %s\n", filePath.c_str());
	_w = (int) cvGetCaptureProperty(videoCap, CV_CAP_PROP_FRAME_WIDTH);
	_h = (int) cvGetCaptureProperty(videoCap, CV_CAP_PROP_FRAME_HEIGHT);

	assert(_w > 0 && _h > 0);
	_timestamp = 0;
}
Exemplo n.º 26
0
void aplicar_original     (const char *archivo_entrada,
                           bool verbose, bool frames,
                           const char *carpeta_frames){
    static size_t bufsize = 1024;
    char namebuff[bufsize + 1];

    const char *filename = basename(archivo_entrada);
    CvCapture *srcVid = abrir_video(archivo_entrada);
	CvSize dst_size;

    dst_size.width = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_WIDTH);
    dst_size.height = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FRAME_HEIGHT);
	double fps = cvGetCaptureProperty(srcVid,CV_CAP_PROP_FPS);

    typedef struct CvVideoWriter CvVideoWriter;
    snprintf(namebuff, bufsize, "%s.original.avi", archivo_entrada);
    printf("\n\n%s\n\n",namebuff);
    CvVideoWriter* dstVid = abrir_writer(namebuff, fps, dst_size);

    if (verbose) {
        cvNamedWindow("procesanding", CV_WINDOW_AUTOSIZE);
    }
    unsigned int framenum = 0;
    while(1) {
        /* Capturo un frame */
        IplImage *frame = cvQueryFrame(srcVid);

        framenum ++;


        if(framenum==100)break;

        cvWriteFrame(dstVid, frame);
        if (frames) {
            /* Escribo el frame */
            snprintf(namebuff, bufsize, "%s/%s.original.%d.bmp",
                                    carpeta_frames, filename, framenum);
            cvSaveImage(namebuff, frame, NULL);
        }
        if (verbose) {
            cvShowImage("procesanding", frame);
            cvWaitKey(1);
        }
    }

    if (verbose) {
        cvDestroyWindow("procesanding");
    }

    cvReleaseVideoWriter(&dstVid);
    cvReleaseCapture(&srcVid);
}
Exemplo n.º 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;
}
Exemplo n.º 28
0
//
// Prints the properties of a CvCapture structure.
//
void printCaptureProperties( CvCapture * capture )
{

	assert( capture != NULL );

	printf( "Capture properties of CvCapture at 0x%08lX:\n"
		"CV_CAP_PROP_POS_MSEC     : %f\n"
		"CV_CAP_PROP_POS_FRAMES   : %f\n"
		"CV_CAP_PROP_POS_AVI_RATIO: %f\n"
		"CV_CAP_PROP_FRAME_WIDTH  : %f\n"
		"CV_CAP_PROP_FRAME_HEIGHT : %f\n"
		"CV_CAP_PROP_FPS          : %f\n"
		"CV_CAP_PROP_FOURCC       : %f\n"
		"CV_CAP_PROP_FRAME_COUNT  : %f\n",
		//( unsigned int ) capture,
		( uint64 ) capture,
		cvGetCaptureProperty( capture, CV_CAP_PROP_POS_MSEC ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_POS_FRAMES ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_POS_AVI_RATIO ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_FPS ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_FOURCC ),
		cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_COUNT ) );
}
Exemplo n.º 29
0
/*
 * Get size of frames in the video stream.
 */
VALUE
rb_get_size(VALUE self)
{
  CvSize size;
  try {
    CvCapture* self_ptr = CVCAPTURE(self);
    size = cvSize((int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_WIDTH),
		  (int)cvGetCaptureProperty(self_ptr, CV_CAP_PROP_FRAME_HEIGHT));
  }
  catch (cv::Exception& e) {
    raise_cverror(e);
  }
  return cCvSize::new_object(size);
}
Exemplo n.º 30
0
main( int argc, char* argv[] ) {

	CvCapture *capture = NULL;	
	capture = cvCreateCameraCapture( -1 );

	IplImage *frames = cvQueryFrame(capture);

	// get a frame size to be used by writer structure
	
	CvSize size = cvSize (
	(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),

	(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
	);

	// declare writer structure
	// use FOURCC ( Four Character Code ) MJPG, the motion jpeg codec
	// output file is specified by first argument
	CvVideoWriter *writer = cvCreateVideoWriter(
	argv[1],

	CV_FOURCC('M','J','P','G'),
	30, // set fps
	size

	);
	
	//Create a new window
	//cvNamedWindow( "Recording ...press ESC to stop !", CV_WINDOW_AUTOSIZE );
	// show capture in the window and record to a file
	// record until user hits ESC key
	while(1) {

	 frames = cvQueryFrame( capture );
	 if( !frames ) break;
	 //cvShowImage( "Recording ...press ESC to stop !", frames );
	 cvWriteFrame( writer, frames );

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

	cvReleaseVideoWriter( &writer );
	cvReleaseCapture ( &capture );
	cvDestroyWindow ( "Recording ...press ESC to stop !");

	return 0;

}