コード例 #1
0
ファイル: cvEyeTracker.c プロジェクト: downbeat/senseye
void Update_Gui_Windows() 
{
  static int first = 1;

  cvShowImage(eye_window, eye_image);
  cvShowImage(original_eye_window, original_eye_image);
  cvReleaseImage(&original_eye_image);
  cvShowImage(scene_window, scene_image);
  cvShowImage(ellipse_window, ellipse_image);
  cvResizeWindow(eye_window,RESOLUTION_WIDTH,RESOLUTION_HEIGHT);
  cvResizeWindow(original_eye_window,RESOLUTION_WIDTH,RESOLUTION_HEIGHT);
  cvResizeWindow(scene_window,RESOLUTION_WIDTH,RESOLUTION_HEIGHT);
  cvResizeWindow(ellipse_window,RESOLUTION_WIDTH,RESOLUTION_HEIGHT);
  // only OpenCV 0.9.6 has the function of cvMoveWindow(), now we are using version 0.9.5
  if (first) {
    cvMoveWindow(eye_window, RESOLUTION_WIDTH, 0);
    cvMoveWindow(scene_window, 2*RESOLUTION_WIDTH, 0);
    cvMoveWindow(ellipse_window, RESOLUTION_WIDTH, RESOLUTION_HEIGHT);
    first = 0;
  }

  cvSetTrackbarPos("Edge Threshold", control_window, pupil_edge_thres);
}
コード例 #2
0
/*!
  Set the window position in the screen.

  \param winx, winy : Position of the upper-left window's border in the screen.

  \exception vpDisplayException::notInitializedError : If the video
  device is not initialized.
*/
void vpDisplayOpenCV::setWindowPosition(int winx, int winy)
{
  if (displayHasBeenInitialized) {
    this->windowXPosition = winx;
    this->windowYPosition = winy;
    cvMoveWindow( this->title, winx, winy );
  }
  else
  {
    vpERROR_TRACE("OpenCV not initialized " ) ;
    throw(vpDisplayException(vpDisplayException::notInitializedError,
                             "OpenCV not initialized")) ;
  }
}
コード例 #3
0
int main(int argc, char *argv[])
{
	IplImage* img = 0; 
	IplImage* img2 = 0;
	int height,width,step,channels;
	uchar *data;
	int i,j,k;
	
	if(argc<2){
		printf("Usage: main <image-file-name>\n\7");
		exit(0);}
	
	// load an image  
	img=cvLoadImage(argv[1]);
	if(!img){
	printf("Could not load image file: %s\n",argv[1]);
	exit(0);
	}
	
	// get the image data
	height    = img->height;
	width     = img->width;
	step      = img->widthStep;
	channels  = img->nChannels;
	data      = (uchar *)img->imageData;
	printf("Processing a %dx%d image with %d channels and widthStep=%d\n",height,width,channels,step); 
	
	cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); // create a window
	cvMoveWindow("mainWin", 100, 100);//offset from the upper-left corner of the screen
	
	// invert the image
	for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
	data[i*step+j*channels+k]=255-data[i*step+j*channels+k];	
	cvShowImage("mainWin1", img );	// show the image
	cvWaitKey(0); // wait for a key

	cvCircle(img, cvPoint(100,100), 20, cvScalar(0,255,0), 1);//draw a circle at (100,100) with a r=20. green lines of width 1
	cvShowImage("mainWin2", img );	// show the image
	cvWaitKey(0); // wait for a key

	img2=cvCreateImage(cvSize(img->width,img->height),IPL_DEPTH_32F,3);//allocates memory for image 2
	cvLaplace( img, img2, 3); //computes Laplacian of img and puts the result on img2. 
	cvShowImage("mainWin3", img2 );// show the image
	cvWaitKey(0); // wait for a key
	
	// release the images
	cvReleaseImage(&img );
	cvReleaseImage(&img2 );
	return 0;
}
コード例 #4
0
ファイル: fill.c プロジェクト: j0sh/thesis
int main(int argc, char **argv)
{
#define NEWIMG(s) cvLoadImage(s, CV_LOAD_IMAGE_COLOR)
    // 19 - 22 are 'similar'
    IplImage *mask = make_mask("bunny.png");
    IplImage *a = NEWIMG("frames/bbb20.png");
    IplImage *b = cvCreateImage(cvGetSize(a), a->depth, a->nChannels);
    cvCopy(a, b, NULL);
#undef NEWIMG
    IplImage *out = fill(a, b, mask);

    cvShowImage("a", a);
    cvShowImage("mask", mask);
    cvShowImage("out", out);
    cvMoveWindow("a", 0, 0);
    cvMoveWindow("mask", 480, 0);
    cvMoveWindow("out", 0, 400);
    cvWaitKey(0);
    cvReleaseImage(&a);
    cvReleaseImage(&b);
    cvReleaseImage(&mask);
    return 0;
}
コード例 #5
0
ファイル: mgui.cpp プロジェクト: JasonLiu0728/MDA-Software
mvWindow:: mvWindow (const char name[]) :
    bin_showImage ("mvWindow - showImage"), _window_number(-1)
{ // this has to be the h file
    assert (strlen(name) < WINDOW_NAME_LEN);
    sprintf (_name, "%s", name);

    cvNamedWindow (_name, CV_WINDOW_AUTOSIZE);

    unsigned i = 0;
    while (i < NUM_SUPPORTED_WINDOWS && WINDOWS_ARRAY[i] == true) 
        i++;                    // find next free slot

    if (i >= NUM_SUPPORTED_WINDOWS) return; // return if no slot
    WINDOWS_ARRAY[i] = true;    // mark slot as used
    _window_number = i;
    
    switch (_window_number) {
        case 0: cvMoveWindow (_name, 400,10); break;
        case 1: cvMoveWindow (_name, 810,10); break;
        case 2: cvMoveWindow (_name, 400,360); break;
        case 3: cvMoveWindow (_name, 810,360); break;
    }
}
コード例 #6
0
ファイル: gaussian.cpp プロジェクト: GunnarHorve/painter
int main(int argc, char* argv[])
{
    //Load an image to transform !!
  IplImage* img = cvLoadImage( "images/lena.jpg" );
  
  // Define two window for showing input image and processed output of an Image.
  cvNamedWindow( "example_input" );
  cvNamedWindow( "example_output" );
  cvNamedWindow( "example_output2");
  cvMoveWindow("example_input", 10, 100);    // to move the window to position 100 100.
  cvMoveWindow("example_output", 600, 100);    // to move the window to position 100 100.
  cvMoveWindow("example_output2", 1200, 100);    // to move the window to position 100 100.
  
  // Show the original image
  cvShowImage("example_input", img);
  
  // Create an image for the output
  IplImage* out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
  IplImage* out2 = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
  
  // Perform a Gaussian blur ( Convolving with 11 X 11 Gaussian).
  cvSmooth( img, out, CV_GAUSSIAN, 11, 11 );
  cvSmooth( img, out2, CV_GAUSSIAN, 21, 21 );
  
  // Show the processed image
  cvShowImage("example_output", out);
  cvShowImage("example_output2", out2);
  
  cvWaitKey(0);
  cvReleaseImage( &img );
  cvReleaseImage( &out );
  cvReleaseImage( &out2 );
  cvDestroyWindow( "example_input" );
  cvDestroyWindow( "example_output" );
  cvDestroyWindow( "example_output2" );
  return 0;
}
コード例 #7
0
void perspectiveTransform() {

    processImage = windowImage;
    
    setVariables();                                                                           //设置四个预设的点
    setPoints();                                                                              //选取图片上的点
    cvDestroyWindow("monitor");
    windowImage = cvCreateImage(cvSize(squareWindowSize,squareWindowSize), IPL_DEPTH_8U, 3);
    cvGetPerspectiveTransform(originalPoints, transPoints, transmat);                         //计算transmat的值
    cvWarpPerspective(processImage , windowImage , transmat);                                 //这一句利用transmat进行变换
    cvNamedWindow("control");
    cvMoveWindow("control", middlewindowX, middlewindowY);
    cvShowImage("control", windowImage);
    cvWaitKey();
    cvDestroyWindow("control");
}
void AdaptiveHistogramCamshift::ShowControlsGUI()
{
  cvNamedWindow(m_controlsGUIWndName.c_str(), 1);
  cvNamedWindow("Trackbars", 1);
  if (!m_showControlsGUI)
  {
    cvMoveWindow(m_controlsGUIWndName.c_str(), m_frameSize.width + 10, 0);
    cvCreateTrackbar(ControlNames[ControlName_VMin], "Trackbars", &m_vMin, 256, 0);
    cvCreateTrackbar(ControlNames[ControlName_VMax], "Trackbars", &m_vMax, 256, 0);
    cvCreateTrackbar(ControlNames[ControlName_SMin], "Trackbars", &m_sMin, 256, 0);
    cvCreateTrackbar(ControlNames[ControlName_SBox], "Trackbars", &m_sBox, 64, 0);
    cvCreateTrackbar(ControlNames[ControlName_AgingFactor], "Trackbars", &m_ageRatio, 100, 0);
    cvSetMouseCallback(m_controlsGUIWndName.c_str(), &AdaptiveHistogramCamshift::OnMouse, &m_id);
  }
  m_showControlsGUI = true;
}
コード例 #9
0
bool _stdcall opencvProcess(LPWSTR csInputPath, LPWSTR csOutputPath)
{
	char inputPath[SIZE] = "";
	WideCharToMultiByte(950, 0, csInputPath, -1, inputPath, SIZE, NULL, NULL);//wchar_t * to char
	char outputPath[SIZE] = "";
	WideCharToMultiByte(950, 0, csOutputPath, -1, outputPath, SIZE, NULL, NULL);//wchar_t * to char *

	//load image
	img = cvLoadImage(inputPath, -1);
	if(!img)
		return false;
	else 
	{
		CvSize size = cvGetSize(img); 

		int xScreen = GetSystemMetrics(SM_CXSCREEN);
		int yScreen = GetSystemMetrics(SM_CYSCREEN);
		
		while(size.width + 100 > xScreen || size.height + 100 > yScreen)
		{
			size.width /= 1.4;
			size.height /= 1.4;
		}//end while
	
		size.height += 90;

		cvNamedWindow(windowName, 0);
		cvResizeWindow(windowName, size.width, size.height); 
		cvMoveWindow(windowName, (xScreen-size.width)/2, (yScreen-size.height)/2 ); 
		int initValueW = W;
		int initValueH = H;
		cvCreateTrackbar("寬", windowName, &initValueW, img->width / 10, onTrackbarW);
		cvCreateTrackbar("高", windowName, &initValueH, img->height / 10, onTrackbarH);
		work();

		cvShowImage(windowName, dst);
		cvWaitKey();
		cvSaveImage(outputPath, dst);
		cvDestroyAllWindows();
		cvReleaseImage(&img);
		cvReleaseImage(&dst);

		return true;
		}//end else
	return false;
}//end opencvProcess
コード例 #10
0
ファイル: main.c プロジェクト: scottellis/shapegen
int main(int argc, char **argv)
{
	int num_cal_images = 32;
	int num_images = 100;

	init_rng();
		
	cvNamedWindow("shapegen", CV_WINDOW_AUTOSIZE);
	cvMoveWindow("shapegen", 10, 10);

	if (generate_cal_image(project_dir, num_cal_images)) {
		draw_loop(project_dir, num_cal_images, num_images);
		//draw_loop(NULL, num_cal_images, 20);
	}

	return 0;
}
コード例 #11
0
 int main(int argc, char** argv) {
    IplImage* image = cvLoadImage(argv[1], 0);
    cvNamedWindow("Ex4_in", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("Ex4_out", CV_WINDOW_AUTOSIZE);
    cvShowImage("Ex4_in", image);
    IplImage* out = doPyrDown(image, IPL_GAUSSIAN_5x5);
    IplImage* out1 = doPyrDown(out, IPL_GAUSSIAN_5x5);
    IplImage* out2 = doCanny(out1, 10, 100, 3);
    cvShowImage("Ex4_out", out2);
    cvMoveWindow("Ex4_out", 0, 0);
    cvReleaseImage(&out);
    cvReleaseImage(&out2);
    cvWaitKey(0);
    cvDestroyWindow("Ex4_in");
    cvDestroyWindow("Ex4_out");
    return 0;
 }
コード例 #12
0
ファイル: Codigo.cpp プロジェクト: AttylaLino/MoscaBranca
int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;

  if(argc<2){
    printf("Uso: NomeDoExecutavel  <NomeDaImagen.formato>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Não foi possível carregar a imagem: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processando uma imagem %dx%d com  %d canais \n",height,width,channels); 

  // Criar uma janela
  cvNamedWindow("Imagem de Saida", CV_WINDOW_AUTOSIZE);
  cvMoveWindow("Imagem de Saida", 100, 100);

  // Inverte a imagem
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k]; //Num entendi muito bem direito

  // Mostrar a Imagem
  cvShowImage("Imagem de Saida", img );

  // wait for a key
  cvWaitKey(0);
	
  // release the image
  cvReleaseImage(&img );
  return 0;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: fern17/Kinect-Test
int main(int argc, char *argv[])
{
  IplImage* img = 0; 
  int height,width,step,channels;
  uchar *data;
  int i,j,k;

  if(argc<2){
    printf("Usage: main <image-file-name>\n\7");
    exit(0);
  }

  // load an image  
  img=cvLoadImage(argv[1]);
  if(!img){
    printf("Could not load image file: %s\n",argv[1]);
    exit(0);
  }

  // get the image data
  height    = img->height;
  width     = img->width;
  step      = img->widthStep;
  channels  = img->nChannels;
  data      = (uchar *)img->imageData;
  printf("Processing a %dx%d image with %d channels\n",height,width,channels); 

  // create a window
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE); 
  cvMoveWindow("mainWin", 100, 100);

  // invert the image
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

  // show the image
  cvShowImage("mainWin", img );

  // wait for a key
  cvWaitKey(0);

  // release the image
  cvReleaseImage(&img );
  return 0;
}
コード例 #14
0
ファイル: GaussianMixture.cpp プロジェクト: elie-moussy/LibPF
/*! \fn void ViewGM(char *nm, int w=320, int h=240)
 *  \brief this function display the 2D gaussian mixture on an image
 */
void GaussianMixture::ViewGM(char *nm, int w, int h)
{
  if(this->dim != 2) cout << "|ERROR|--> GaussianMixture (ViewGM) \t:\t dim not match to display on 2D image" << endl;
  IplImage *dsp = cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,3);
  double v[2];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      {
	v[0] = j;
	v[1] = i;
	double prob = this->Eval(v);
	cvSet2D(dsp,i,j,SCalcTeint((int)(prob/glist[0]->coeff*255)));
      }
  cvNamedWindow(nm,0);
  cvMoveWindow(nm,0,0);
  cvShowImage(nm,dsp);
  cvWaitKey(5);
}
コード例 #15
0
// Initialize window and variables
void Painting::drawInit(Painting* p)
{
    paint = p;  // Save pointer to class object

    // Create a window
    namedWindow(WindowName);
    cvSetMouseCallback(WindowName, mouse, NULL);
    cvMoveWindow(WindowName, 50, 50);
    IplImage* image = cvCreateImage(cvSize(500,500),IPL_DEPTH_8U,3);
    cvZero( image );
    cvRectangleR(image,cvRect(0,0,500,500),cvScalar(255,255,255), -1);
    cvResizeWindow(WindowName, 500, 500);

    mImage = image;
    mSelect = 0;

    mLeftButton = cvRect(10, 10, 100, 100);
    mRightButton = cvRect(490, 10, 100, 100);
}
コード例 #16
0
ファイル: GaussianMixture.cpp プロジェクト: elie-moussy/LibPF
/*! \fn void ViewFromDraw(int nbpt, char *nm, int w=320, int h=240)
 *  \brief this function display a 2D gaussian mixture on an image with weighted points
 */
void GaussianMixture::ViewFromDraw(int nbpt, char *nm, int w, int h)
{
  if(this->dim != 2) cout << "|ERROR|--> GaussianMixture (ViewFromDraw) \t:\t dim not match to display on 2D image" << endl;
  IplImage *dsp = cvCreateImage(cvSize(w,h),IPL_DEPTH_8U,3);
  double v[2];
  for(int i=0;i<nbpt;i++)
    {
      //cout << "1 : " << v[0] << "," << v[1] << "\n";
      this->Draw(v);
      //cout << "2 : " << v[0] << "," << v[1] << "\n";     
      double prob = this->Eval(v);
      if((v[1]>=0)&&(v[1]<h)&&(v[0]>=0)&&(v[0]<w))
	cvSet2D(dsp,(int)v[1],(int)v[0],SCalcTeint((int)(prob/glist[0]->coeff*255)));
    }

  cvNamedWindow(nm,0);
  cvMoveWindow(nm,w+10,0);
  cvShowImage(nm,dsp);
  cvWaitKey(5);
  cvReleaseImage(&dsp);
}
コード例 #17
0
void compute_and_display_image_corners(char * imageName, CvSize * imageSize, CvSize chessboardSize, CvPoint2D32f * cornersArrayToFillIn)
{
    IplImage * img = 0;
    int cornersCount = 0;
    int patternWasFound = 0;
    int i;


    img = cvLoadImage(imageName, 1);

    *imageSize = cvGetSize(img); // useful only for calibration function

    //initialisation of the given array
    for(i=0;i<chessboardSize.height*chessboardSize.width;i++){ cornersArrayToFillIn[i].x= 0; cornersArrayToFillIn[i].y= 0; }

    printf("OK1\n");
    // core algorithm
    patternWasFound = cvFindChessboardCorners(img, chessboardSize, cornersArrayToFillIn, &cornersCount, 0);

    printf("OK2\n");

    // display_array_values(cornersArrayToFillIn,chessboardSize.height*chessboardSize.width);
    improve_precision(img, cornersArrayToFillIn, cornersCount);
    // display_array_values(cornersArrayToFillIn,chessboardSize.height*chessboardSize.width);

    // visual only part

    cvDrawChessboardCorners(img, chessboardSize, cornersArrayToFillIn, cornersCount, patternWasFound);
    cvNamedWindow(imageName, CV_WINDOW_AUTOSIZE);
    cvMoveWindow(imageName, 100, 100);
    cvShowImage(imageName, img );
    cvWaitKey(200);
    cvDestroyWindow(imageName);


    // end
    cvReleaseImage(&img );

}
コード例 #18
0
ファイル: sift_test.cpp プロジェクト: dedan/obj_att
int main() {

    IplImage* lena = cvLoadImage("lena.tif", 0);
    Image img_sift = CreateImage(lena->height, lena->width);
    for(int r = 0; r < lena->height; ++r)
    {
        for(int c = 0; c < lena->width; ++c)
        {

            CvScalar s = cvGet2D(lena,c,r);
            img_sift->pixels[r*img_sift->stride+c] =
                (s.val[0] + s.val[1] + s.val[2]) / (3.*255);
        }
    }
    Keypoint keypts = GetKeypoints(img_sift);
    Keypoint key = keypts;
    while(key)
    {
        cvRectangle(lena,
                    cvPoint(key->row-1 ,key->col-1),
                    cvPoint(key->row+1 ,key->col+1),
                    cvScalar(255,0,0), 1);
        key = key->next;
    }

    FreeKeypoints(keypts);
    DestroyAllResources();
    cvNamedWindow("lena", 1);
    cvMoveWindow("lena", 800, 200);

    cvShowImage("lena", lena);

    cvWaitKey(0);

    cvDestroyAllWindows();
    cvReleaseImage(&lena);


}
コード例 #19
0
ファイル: Display.cpp プロジェクト: animecomico/kth-rgbd
int Display::showPreview(IplImage *pImage1, IplImage *pImage2)
{
	if (Config::_FeatureDisplay) {
		// create window if necessary
		if (! _displayingPreview) {
			cvNamedWindow("Preview", CV_WINDOW_NORMAL);
			cvResizeWindow("Preview", NBPIXELS_WIDTH, NBPIXELS_HEIGHT*2);
			cvMoveWindow("Preview", FEAT_POSX, FEAT_POSY); // offset from the UL corner of the screen
			_displayingPreview = true;
		}
		// display image
		if (pImage1 != NULL) {
			memcpy(_pImgFeatures->imageData, pImage1->imageData, pImage1->imageSize);
			if (pImage2 != NULL) {
				// assume both have same size !
				memcpy(_pImgFeatures->imageData+(pImage1->imageSize), pImage2->imageData, pImage2->imageSize);
			}
		}
		cvShowImage("Preview", _pImgFeatures);
		return cvWaitKey(CV_WAITKEY_TIMEOUT);
	}
	return -1;
}
コード例 #20
0
ファイル: VideoFeed.cpp プロジェクト: BIURoboCup/RoboCup2016
/*
 * Description: Constructor.
 * It creates a new window to display the new frame.
 * Parameters: int windowNumber - the window number in the camera's streaming list
 * Return Value: None.
 */
VideoFeed::VideoFeed(int windowNumber, IplImage* Current_Frame,
		const char* windowName) {
	cout << "Video Feed Constructor" << "\n";
	//char chWindownumber[2] = {windowNumber + '0', '\0'};	// convert int to char

	//strcpy(m_windowName, "Debug ");							// window name setup
	//strcat(m_windowName, chWindownumber);					// Concatenate window number to its name

	strcpy(m_windowName, windowName); // window name setup

	cvNamedWindow(m_windowName, CV_WINDOW_AUTOSIZE); // create the new window

	m_printPixel = false;
	cvSetMouseCallback(m_windowName, Mouse_Pos_Print_Pixel,
			(void*) Current_Frame);

	m_Frame = Current_Frame;

	int windowX = 10 + 324 * (windowNumber % 3);
	int windowY = 20 + 280 * (windowNumber / 3);
	cvMoveWindow(m_windowName, windowX, windowY);

}
コード例 #21
0
ファイル: video.cpp プロジェクト: atupal/opencv_learn
int readVideo(char *fileName)
{
	printf("%s\n", fileName);
	CvCapture *video_capture = cvCreateFileCapture(fileName);
	IplImage *img;
	cvNamedWindow("win_1", CV_WINDOW_AUTOSIZE);
	cvMoveWindow("win_1", 100, 100);

	int flag = 1;

	while (flag != 27) {
		img = cvQueryFrame(video_capture);
		if (img) {
			cvShowImage("win_1", img);
			flag = cvWaitKey(30);
		}
	}
	
	cvReleaseCapture(&video_capture);
	cvDestroyWindow("win_1");

	return 0;
}
コード例 #22
0
int main() {


CvRect rect;
IplImage* frame=cvLoadImage("lena.jpg",1);


//rect.x = 100;
//rect.y = 100;
//rect.width = 300;
//rect.height = 400;
rect = cvRect( 200, 200, 200, 200 );


cvSetImageROI(frame, rect );
IplImage *dst = cvCreateImage( cvGetSize( frame ), frame->depth, 1 );

cvNamedWindow("My Window");
cvNamedWindow("111");
cvCvtColor( frame, dst, CV_BGR2GRAY);

cvResetImageROI( frame );

cvShowImage("My Window",dst);
cvShowImage("111",frame);
cvMoveWindow("111",400,400);

cvSaveImage("C:/Users/Terry/Desktop/part_ROI_img.jpg",dst);

cvWaitKey();
cvReleaseImage( &frame );
cvReleaseImage( &dst );

cvDestroyWindow("My Window");
cvDestroyWindow("111");
return 0;
}
コード例 #23
0
ファイル: Display.cpp プロジェクト: animecomico/kth-rgbd
int Display::showOutOfSync(IplImage *pImage1, IplImage *pImage2)
{
	CvFont font;
	double hScale=2;
	double vScale=2;
	int    lineWidth=2;

	if (_displayingPreview) {
		cvDestroyWindow("Preview");
		_displayingPreview = false;
	}

	if (Config::_FeatureDisplay && _pImgInfo != NULL) {
		// score is not valid
		updateScore(-1);
		cvShowImage("Quality", _pImgInfo);
	}

	if (! _displayingFeatures) {
		// create feature windows
		cvNamedWindow("Features", CV_WINDOW_NORMAL);
		cvResizeWindow("Features", NBPIXELS_WIDTH, NBPIXELS_HEIGHT*2);
		cvMoveWindow("Features", FEAT_POSX, FEAT_POSY); // offset from the UL corner of the screen
		_displayingFeatures = true;
	}
	// update image buffer by stacking the 2 frames
	if (pImage1 != NULL) {
		memcpy(_pImgFeatures->imageData, pImage1->imageData, pImage1->imageSize);
		if (pImage2 != NULL)
			memcpy(_pImgFeatures->imageData+(pImage1->imageSize), pImage2->imageData, pImage2->imageSize);
	}
	// define a font to write some text
	cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, hScale,vScale, 0, lineWidth);
	cvPutText(_pImgFeatures, "SYNC LOST", cvPoint(40, NBPIXELS_HEIGHT+200), &font, cvScalar(0,0,255));
	cvShowImage("Features", _pImgFeatures);
	return cvWaitKey(CV_WAITKEY_TIMEOUT);
}
コード例 #24
0
/** void InitGraphWindow( CONF_2D StartConf, CONF_2D GoalConf );
 ***********************************************************
 * Date		: 2012/03/29
 * Author	: Kohei Kojima
 * Note		: Initialize Graph Window
 ***********************************************************/	
void CGraphRendering::InitGraphWindow(CONF_2D StartConf, CONF_2D GoalConf)
{
    //描画用IplImageバッファの確保
    img = cvCreateImage(cvSize(WIDTH, HEIGHT), IPL_DEPTH_8U, 3);
    
    //画像表示ウィンドウの準備
    cvNamedWindow( WINDOW_NAME, CV_WINDOW_AUTOSIZE );

    //画像表示ウィンドウの出現位置指定
    cvMoveWindow( WINDOW_NAME, 50, 50 );

	cvSetZero(img);

	cvCircle(img, cvPoint((int)StartConf.x, (int)StartConf.y), 3, cvScalar(0, 0, 255), 2, 8, 0);
	cvCircle(img, cvPoint((int)GoalConf.x, (int)GoalConf.y), TOLERANCE, cvScalar(0, 0, 255), 2, 8, 0);

	cvLine(img, cvPoint(MAX_X/3, MAX_Y/3), cvPoint(2*MAX_X/3, MAX_Y/3), cvScalar(0, 255, 0), 3, 8, 0);
	cvLine(img, cvPoint(MAX_X/3, MAX_Y/3), cvPoint(MAX_X/3, 2*MAX_Y/3), cvScalar(0, 255, 0), 3, 8, 0);
	cvLine(img, cvPoint(MAX_X/3, 2*MAX_Y/3), cvPoint(2*MAX_X/3, 2*MAX_Y/3), cvScalar(0, 255, 0), 3, 8, 0);
	cvLine(img, cvPoint(2*MAX_X/3, MAX_Y/3), cvPoint(2*MAX_X/3, 2*MAX_Y/3), cvScalar(0, 255, 0), 3, 8, 0);

	cvShowImage( WINDOW_NAME, img );
	cvWaitKey(10);
}
コード例 #25
0
ファイル: canny.cpp プロジェクト: hone/school
int main( int argc, char * argv[] )
{
	const char * WINDOW_NAME = "Original Image";

	// x is low
	// y is high
	std::pair< int, int > thresh = std::make_pair( THRESH_MIN, THRESH_MAX);

	if( argc < 2 )
	{
		std::cerr << "Not enough parameters.\n";
		exit( -1 );
	}
	ImageRAII image( argv[1] );

	cvNamedWindow( WINDOW_NAME );
	cvShowImage( WINDOW_NAME, image.image );
	cvMoveWindow( WINDOW_NAME, 0, 0 );

	ImageRAII edge_detection_image = canny( image.image, thresh, SIGMA );

	cvWaitKey( 0 );
	return 0;
}
コード例 #26
0
void HoleDetector::init(ros::NodeHandle* handle, const char * cam_image_topic)
{
    image_transport::ImageTransport transportedHandle(*handle);
    mImagePub = transportedHandle.advertise("/hole_detection/hole_image", 1);
    TargetPosition = handle->advertise<hole_detection::PositionXY>("/hole_detection/target_XY",1);
    ros::Duration(1.0).sleep();

    targetLock = false;

    ros::spinOnce();
    mImageSub = handle->subscribe(cam_image_topic, 1, &HoleDetector::getImageCallback, this);

    cv::namedWindow("original", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("original", 10, 250);
    cv::namedWindow("grayscale", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("grayscale", 1000, 250);
    cv::namedWindow("binary", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("binary", 10, 500);
    cv::namedWindow("binary_filtered", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("binary_filtered", 1000, 500);
    cv::namedWindow("simple_blob", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("simple_blob", 10, 750);
    cv::namedWindow("targeted", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
    cvMoveWindow("targeted", 1000, 750);
    
    
//OpenCV HighGUI call to create a display window on start-up (set for DUAL monitors)
//    cv::namedWindow("original", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("original", 2000, 250); 
//    cv::namedWindow("grayscale", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("grayscale", 3000, 250); 
//    cv::namedWindow("binary", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("binary", 2000, 500); 
//    cv::namedWindow("binary_filtered", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("binary_filtered", 3000, 500); 
//    cv::namedWindow("simple_blob", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("simple_blob", 2000, 750); 
//    cv::namedWindow("targeted", CV_WINDOW_NORMAL | CV_WINDOW_KEEPRATIO);
//    cvMoveWindow("targeted", 3000, 750); 
}
コード例 #27
0
ファイル: Diff2.cpp プロジェクト: KingBing/OpenCV_OLD
int diff2_main( int argc, char** argv )
{
	//声明IplImage指针
	IplImage* pFrame = NULL; 
	IplImage* pFrImg = NULL;
	IplImage* pBkImg = NULL;

	CvMat* pFrameMat = NULL;
	CvMat* pFrMat = NULL;
	CvMat* pBkMat = NULL;

	CvCapture* pCapture = NULL;

	int nFrmNum = 0;

	//创建窗口
	cvNamedWindow("video", 1);
	cvNamedWindow("background",1);
	cvNamedWindow("foreground",1);
	//使窗口有序排列
	cvMoveWindow("video", 30, 0);
	cvMoveWindow("background", 360, 0);
	cvMoveWindow("foreground", 690, 0);


	if( !(pCapture = cvCaptureFromAVI("bike.avi")))
	{
		//pCapture = cvCaptureFromCAM(-1))
		fprintf(stderr, "Can not open camera.\n");
		return -2;
	}


	//逐帧读取视频
	while(pFrame = cvQueryFrame( pCapture ))
	{
		nFrmNum++;

		//如果是第一帧,需要申请内存,并初始化
		if(nFrmNum == 1)
		{
			pBkImg = cvCreateImage(cvSize(pFrame->width, pFrame->height),  IPL_DEPTH_8U,1);
			pFrImg = cvCreateImage(cvSize(pFrame->width, pFrame->height),  IPL_DEPTH_8U,1);

			pBkMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);
			pFrMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);
			pFrameMat = cvCreateMat(pFrame->height, pFrame->width, CV_32FC1);

			//转化成单通道图像再处理
			cvCvtColor(pFrame, pBkImg, CV_BGR2GRAY);
			cvCvtColor(pFrame, pFrImg, CV_BGR2GRAY);

			cvConvert(pFrImg, pFrameMat);
			cvConvert(pFrImg, pFrMat);
			cvConvert(pFrImg, pBkMat);
		}
		else
		{
			cvCvtColor(pFrame, pFrImg, CV_BGR2GRAY);
			cvConvert(pFrImg, pFrameMat);
			//高斯滤波先,以平滑图像
			//cvSmooth(pFrameMat, pFrameMat, CV_GAUSSIAN, 3, 0, 0);

			//当前帧跟背景图相减
			cvAbsDiff(pFrameMat, pBkMat, pFrMat);

			//二值化前景图
			cvThreshold(pFrMat, pFrImg, 60, 255.0, CV_THRESH_BINARY);

			//进行形态学滤波,去掉噪音  
			//cvErode(pFrImg, pFrImg, 0, 1);
			//cvDilate(pFrImg, pFrImg, 0, 1);

			//更新背景
			cvRunningAvg(pFrameMat, pBkMat, 0.003, 0);
			//将背景转化为图像格式,用以显示
			cvConvert(pBkMat, pBkImg);

			//显示图像
			cvShowImage("video", pFrame);
			cvShowImage("background", pBkImg);
			cvShowImage("foreground", pFrImg);

			//如果有按键事件,则跳出循环
			//此等待也为cvShowImage函数提供时间完成显示
			//等待时间可以根据CPU速度调整
			if( cvWaitKey(20) >= 0 )
			{
				break;
			}
		}
	}
	cvWaitKey();

	//销毁窗口
	cvDestroyWindow("video");
	cvDestroyWindow("background");
	cvDestroyWindow("foreground");

	//释放图像和矩阵
	cvReleaseImage(&pFrImg);
	cvReleaseImage(&pBkImg);

	cvReleaseMat(&pFrameMat);
	cvReleaseMat(&pFrMat);
	cvReleaseMat(&pBkMat);

	cvReleaseCapture(&pCapture);

	return 0;
}
コード例 #28
0
ファイル: main.c プロジェクト: RokIrt/HandGesture
int main(int argc,char ** argv){
	int key,t;
	double *Features;
	//code to record video
	CvVideoWriter *writer=0;
	int isColor=1;
	int fps=10;
	int frameW=640;
	int frameH=480;
	writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'),fps,cvSize(frameW,frameH),isColor);
	CvMat *mat=cvCreateMat(8,8,CV_64FC1);
	char *filenamesCov = "../../../fourier/fourier/Variances";
	char * FileMeans = "../../../fourier/fourier/Means.txt";
	int numGestures;
	numGestures=11;
	int numTraining=80;	
	int numFeatures=8;
	//CvArr** invCovMatrices= (CvArr **)malloc(sizeof(CvArr *)*numGestures);
	CvArr** eigenVects= (CvArr **)malloc(sizeof(CvArr *)*numGestures);
	CvArr** Means=(CvArr **)malloc(sizeof(CvArr *)*numGestures);
	CvArr** eigenVals=(CvArr **)malloc(sizeof(CvArr*)*numGestures);
	//end record video       
	int indx[] = {6,11,12,14,15,22,27,28,33,36,42}; 
	//5, a, b, c,caps,g,l,LC,p,RC,v,

	CvCapture* capture = NULL;
	cascade = (CvHaarClassifierCascade*)cvLoad( "../NewTrained.xml",
	0, 0, 0 );	
	storage = cvCreateMemStorage(0); 
	IplImage* img;
	IplImage* img1;
	IplImage* img2;
	IplImage* imb;

	if(NULL==(capture = cvCaptureFromCAM(1))){
		printf("\nError on cvCaptureFromCAM");
		return -1;
	}
	
	train(Means,eigenVects,eigenVals,numGestures,19,numFeatures,indx);
	fprintf(stderr,"blahblah\n");
	//ReadInData(filenamesCov,FileMeans,invCovMatrices,Means,numGestures,numFeatures);
	//-----
	cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Capture2", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Capture3", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Window",CV_WINDOW_AUTOSIZE);	

	cvMoveWindow("Capture", 550, 250);
	cvMoveWindow("Capture2",850, 50);
	cvMoveWindow("Capture3",100,500);
	cvMoveWindow("Capture4",500,600);

	for(;;){
		if(NULL==(img=cvQueryFrame(capture))){
			printf("\nError on cvQueryFrame");
		break;
		}

	
		img1=detect_and_draw(img,1);
	    img2=binary_threshold_hsl(img1);
		
		cvShowImage("Capture3",img2);
		cvShowImage("Capture", img1);
		cvShowImage("Capture2",img);
		if(HAND==1)
		{
			
			t=simpleHuRecognize(img2,11);
		}
		if(HAND==1)
		{
			fprintf(stderr,"Found a hand. The gesture recognized is : %c\n",(char) Gest[t]);
			//imb=cvCreateImage("",8,1);
		}
		cvWriteFrame(writer,img1);
		key = cvWaitKey(10);

		if(key==0x1b)
			break;
	}

	cvReleaseCapture(&capture);
	cvDestroyWindow("Capture");
	cvDestroyWindow("Capture2");
	cvDestroyWindow("Capture3");

	cvReleaseImage( &img );
	cvReleaseImage(&img1);

	cvWaitKey(0);
}
コード例 #29
0
ファイル: Gui.cpp プロジェクト: royendgel/tracker_opentld
void Gui::init()
{
    cvNamedWindow(m_window_name.c_str(), CV_WINDOW_AUTOSIZE);
    cvMoveWindow(m_window_name.c_str(), 100, 100);
}
コード例 #30
0
bool _stdcall opencvProcess(LPWSTR csInputPath, LPWSTR csOutputPath)
{
	char inputPath[SIZE] = "";
	WideCharToMultiByte(950, 0, csInputPath, -1, inputPath, SIZE, NULL, NULL);//wchar_t * to char
	char outputPath[SIZE] = "";
	WideCharToMultiByte(950, 0, csOutputPath, -1, outputPath, SIZE, NULL, NULL);//wchar_t * to char *

	//load image
	img = cvLoadImage(inputPath, -1);
	if(!img)
		return false;
	else 
	{
		if(img->nChannels == 1)//if gray img
		{
			cvReleaseImage(&img);
			img = cvLoadImage(inputPath, 1);
		}//end if

		//read color from file
		char rgbPath[SIZE] = "";
		sprintf(rgbPath, "%s\\InstaFilter\\adjustRGB.if", getenv("temp"));
		FILE *rgb = fopen(rgbPath, "rb");
		if(!rgb) return false;
		//read
		int randValue[6];
		char data[SIZE];
		fgets(data, SIZE, rgb);
		char *token = strtok(data, " ");
		for(int i = 0 ; i < sizeof(randValue)/sizeof(*randValue) && token ; i++)
		{
			randValue[i] = atoi(token);
			token = strtok(NULL, " ");
		}//end for
		fclose(rgb);
		//get color

		CvSize size = cvGetSize(img); 

		int xScreen = GetSystemMetrics(SM_CXSCREEN);
		int yScreen = GetSystemMetrics(SM_CYSCREEN);
		
		while(size.width + 100 > xScreen || size.height + 100 > yScreen)
		{
			size.width /= 1.4;
			size.height /= 1.4;
		}//end while

		cvNamedWindow(windowName, 0);
		cvResizeWindow(windowName, size.width, size.height); 
		cvMoveWindow(windowName, (xScreen-size.width)/2, (yScreen-size.height)/2 ); 

		CvSize panelSize = cvSize(600, 135);
		cvNamedWindow(ctrlPanel1, 1);
		cvNamedWindow(ctrlPanel2, 1);
		cvResizeWindow(ctrlPanel1, panelSize.width, panelSize.height);
		cvResizeWindow(ctrlPanel2, panelSize.width, panelSize.height);
		cvMoveWindow(ctrlPanel1, (xScreen-size.width)/2, (yScreen-size.height)/2 ); 
		cvMoveWindow(ctrlPanel2, (xScreen-size.width)/2 + 100, (yScreen-size.height)/2 + 100 ); 
		cvCreateTrackbar("增加紅", ctrlPanel1, randValue, 255, work);
		cvCreateTrackbar("增加綠", ctrlPanel1, randValue+1, 255, work);
		cvCreateTrackbar("增加藍", ctrlPanel1, randValue+2, 255, work);
		cvCreateTrackbar("減少紅", ctrlPanel2, randValue+3, 255, work);
		cvCreateTrackbar("減少綠", ctrlPanel2, randValue+4, 255, work);
		cvCreateTrackbar("減少藍", ctrlPanel2, randValue+5, 255, work);
		cvShowImage(ctrlPanel1, NULL);
		cvShowImage(ctrlPanel2, NULL);
		work(0);

		cvWaitKey(0);
		//release
		cvSaveImage(outputPath, des);

		cvReleaseImage(&img);
		cvReleaseImage(&des);
		cvDestroyAllWindows();

		return true;
	}//end else
	return false;
}//end opencvProcess