最も簡単な動画への変換  「画素値の直接操作 IplImage」を例に

コードが短いので動画にするのは簡単だ。
簡単だったのでカメラのキャプチャ画面は2つにした。
#include <cv.h>
#include <highgui.h>
 
int
main (int argc, char **argv)
{
  int x, y;
  uchar p[3];
  IplImage *img;
  CvCapture *capture;//(1)追加
 
  //if (argc != 2 || (img = cvLoadImage (argv[1], CV_LOAD_IMAGE_COLOR)) == 0)
  // return -1;
  capture = cvCreateCameraCapture (0);//(2)追加
  cvNamedWindow ("Image", CV_WINDOW_AUTOSIZE);//(3)追加
  cvNamedWindow ("Image_moto", CV_WINDOW_AUTOSIZE);//(4)追加
 
  while (1) {//(5)追加
      img = cvQueryFrame (capture);//(7)追加
      cvShowImage ("Image_moto", img);//(8)追加
      // (1)画素値(R,G,B)を順次取得し,変更する
      for (y = 0; y < img->height; y++)
	{
	  for (x = 0; x < img->width; x++)
	    {
	      /* 画素値を直接操作する一例 */
	      p[0] = img->imageData[img->widthStep * y + x * 3];	// B
	      p[1] = img->imageData[img->widthStep * y + x * 3 + 1];	// G
	      p[2] = img->imageData[img->widthStep * y + x * 3 + 2];	// R
	      img->imageData[img->widthStep * y + x * 3] =
		cvRound (p[0] * 0.6 + 10);
	      img->imageData[img->widthStep * y + x * 3 + 1] =
		cvRound (p[1] * 1.0);
	      img->imageData[img->widthStep * y + x * 3 + 2] =
		cvRound (p[2] * 0.0);
	    }
	}
 
      cvShowImage ("Image", img);
      int key = cvWaitKey (10);//(9)追加
      if (key >= 0)break;//(10)追加
    }//()追加
 
  cvDestroyWindow ("Image");
  cvDestroyWindow ("Image_moto");//(11)追加
  //cvReleaseImage (&img);
 
  return 0;
}
最終更新:2010年02月05日 15:52
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。