[ create a new paste ] login | about

Link: http://codepad.org/Bz68YlSw    [ raw code | output | fork ]

C, pasted on Jul 2:
#include <cv.h>
#include <highgui.h>


#pragma comment(lib,"cv.lib")
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cvaux.lib")
#pragma comment(lib,"highgui.lib")

int main (int argc, char **argv){
  int i, j;
  int hist_size = 256, ch_width = 257;
  float range_0[] = { 0, 256 };
  float *ranges[] = { range_0 };
  IplImage *src_img = 0, *dst_img[3], *hist_img, *view;
  CvHistogram *hist;
  CvCapture *capture = 0;
  int keyin;

  capture = cvCreateCameraCapture(0);
  src_img = cvQueryFrame (capture);
  for (i = 0; i < 3; i++) {
	dst_img[i] = cvCreateImage (cvSize (src_img->width, src_img->height), src_img->depth, 1);
  }
  view = cvCreateImage( cvSize(src_img->width/2,src_img->height/2),IPL_DEPTH_8U, 1);

  // ヒストグラム構造体,ヒストグラム画像領域を確保
  hist = cvCreateHist (1, &hist_size, CV_HIST_ARRAY, ranges, 1);
  hist_img = cvCreateImage (cvSize (ch_width * 3, 200), 8, 3);

  cvNamedWindow("Image", CV_WINDOW_AUTOSIZE);
  cvNamedWindow("R", CV_WINDOW_AUTOSIZE);
  cvNamedWindow("G", CV_WINDOW_AUTOSIZE);
  cvNamedWindow("B", CV_WINDOW_AUTOSIZE);
  cvNamedWindow("Histogram", CV_WINDOW_AUTOSIZE);

  int flag = 1;
  int stopflag=0;
  while(flag == 1){
	  if (stopflag == 0)
		src_img = cvQueryFrame (capture);
	//  src_img=cvLoadImage("test.bmp",1);
	  // カラー入力画像をBGRに分解
	  cvSplit (src_img, dst_img[0], dst_img[1], dst_img[2], NULL);

	  // ヒストグラム画像の初期化
	  cvSet (hist_img, cvScalarAll(255), 0);
	  cvLine(hist_img, cvPoint(256,0), cvPoint(256,255),CV_RGB(0,0,0),1,8,0);
	  cvLine(hist_img, cvPoint(256+258,0), cvPoint(256+258,255),CV_RGB(0,0,0),1,8,0);
	  for (i = 0; i < 3; i++) {
		// ヒストグラムの計算
		//  /10としているのは表示するグラフの縦軸方向の大きさを見やすくするため
	    // 実際の画像に合わせて変更するとよい
		cvCalcHist (&dst_img[i], hist, 0, NULL);
		cvScale (hist->bins, hist->bins, ((double) hist_img->height) /((src_img->width)*(src_img->height)/10), 0);
		// ヒストグラムの描画
		switch(i){
			case 0: for (j = 0; j < hist_size; j++)
						cvLine(hist_img, cvPoint(j +(i*ch_width), hist_img->height),
						cvPoint(j +(i*ch_width), hist_img->height - cvRound (cvGetReal1D (hist->bins, j))), CV_RGB(0,0,255), 1, 8, 0);
					break;
			case 1: for (j = 0; j < hist_size; j++)
						cvLine(hist_img, cvPoint(j +(i*ch_width), hist_img->height),
						cvPoint(j +(i*ch_width), hist_img->height - cvRound (cvGetReal1D (hist->bins, j))), CV_RGB(0,255,0), 1, 8, 0);
					break;
			case 2: for (j = 0; j < hist_size; j++)
						cvLine(hist_img, cvPoint(j +(i*ch_width), hist_img->height),
						cvPoint(j +(i*ch_width), hist_img->height - cvRound (cvGetReal1D (hist->bins, j))), CV_RGB(255,0,0), 1, 8, 0);
					break;
		}
	  }

	  // ヒストグラム画像を表示,キーが押されたときに終了や保存
	  cvShowImage("Image", src_img);
	  cvResize(dst_img[0],view,CV_INTER_CUBIC); 
	  cvShowImage("B", view);
	  cvResize(dst_img[1],view,CV_INTER_CUBIC); 
	  cvShowImage("G", view);
	  cvResize(dst_img[2],view,CV_INTER_CUBIC); 
	  cvShowImage ("R", view);
	  cvShowImage("Histogram", hist_img);
	  keyin=cvWaitKey(1);
	  if (keyin=='q'){
		  flag = 0;
	  };
	  if (keyin == 's'){
		  if (stopflag == 0) stopflag = 1;
		  else               stopflag = 0;
	  }

  }

  cvDestroyAllWindows();
  cvReleaseImage(&src_img);
  cvReleaseImage(&hist_img);
  cvReleaseImage(&view);
  for (i = 0; i < 3; i++){
    cvReleaseImage(&dst_img[i]);
  }
  cvReleaseHist(&hist);

  return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Line 15: error: cv.h: No such file or directory
Line 20: error: highgui.h: No such file or directory
In function 'main':
Line 15: error: 'IplImage' undeclared (first use in this function)
Line 15: error: (Each undeclared identifier is reported only once
Line 15: error: for each function it appears in.)
Line 15: error: 'src_img' undeclared (first use in this function)
Line 15: error: 'dst_img' undeclared (first use in this function)
Line 15: error: 'hist_img' undeclared (first use in this function)
Line 15: error: 'view' undeclared (first use in this function)
Line 16: error: 'CvHistogram' undeclared (first use in this function)
Line 16: error: 'hist' undeclared (first use in this function)
Line 17: error: 'CvCapture' undeclared (first use in this function)
Line 17: error: 'capture' undeclared (first use in this function)
Line 25: error: 'IPL_DEPTH_8U' undeclared (first use in this function)
Line 28: error: 'CV_HIST_ARRAY' undeclared (first use in this function)
Line 31: error: 'CV_WINDOW_AUTOSIZE' undeclared (first use in this function)
Line 75: error: 'CV_INTER_CUBIC' undeclared (first use in this function)


Create a new paste based on this one


Comments: