Exemplo n.º 1
0
int main(int argc, char **argv)
{
	IplImage *img_rgb = cvLoadImage(argv[1]);
	IplImage *img_gry =
		cvCreateImage(cvSize(img_rgb->width, img_rgb->height), img_rgb->depth,
					  1);
	cvCvtColor(img_rgb, img_gry, CV_BGR2GRAY);
	IplImage *img_pyr = doPyrDown(img_gry, IPL_GAUSSIAN_5x5);
	IplImage *img_pyr2 = doPyrDown(img_pyr, IPL_GAUSSIAN_5x5);
	IplImage *img_cny = doCanny(img_pyr2, 10, 100, 3);

	cvNamedWindow("Example Gray", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Example Pyr", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Example Canny", CV_WINDOW_AUTOSIZE);
	cvShowImage("Example Gray", img_gry);
	cvShowImage("Example Pyr", img_pyr2);
	cvShowImage("Example Canny", img_cny);
	cvWaitKey(0);
	cvReleaseImage(&img_rgb);
	cvReleaseImage(&img_gry);
	cvReleaseImage(&img_pyr);
	cvReleaseImage(&img_pyr2);
	cvReleaseImage(&img_cny);
	cvDestroyWindow("Example Gray");
	cvDestroyWindow("Example Pyr");
	cvDestroyWindow("Example Canny");

	return 0;
}
Exemplo n.º 2
0
void ImageApp::setupUi(){
   imageLabel = new QLabel();
   originalButton = new QPushButton("打开图像");
   connect(originalButton, SIGNAL(clicked()), this, SLOT(doOpenImage()));
   //connect(originalButton, SIGNAL(clicked()), this, SLOT(showOriginalImage()));

   blurButton = new QPushButton("高斯模糊");
   connect(blurButton, SIGNAL(clicked()), this, SLOT(doGaussianBlur()));

   cannyButton = new QPushButton("边缘检测");
   connect(cannyButton, SIGNAL(clicked()), this, SLOT(doCanny()));

   slicButton = new QPushButton("超像素分割");
   connect(slicButton, SIGNAL(clicked()), this, SLOT(doSLIC()));

   quitButton = new QPushButton("退出");
   connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));

   buttonsLayout = new QVBoxLayout();  // 实例化一个QVBoxLayout对象,用于放置各个按钮
   buttonsLayout->addWidget(originalButton);
   buttonsLayout->addWidget(blurButton);
   buttonsLayout->addWidget(cannyButton);
   buttonsLayout->addWidget(slicButton);
   buttonsLayout->addStretch();  //创建一个可伸缩的box
   buttonsLayout->addWidget(quitButton);

   mainLayout = new QHBoxLayout();
   mainLayout->addWidget(imageLabel);

   if (originalImage.data) {
       mainLayout->addLayout(buttonsLayout);
   }
   setLayout(mainLayout);
   setWindowTitle("图像处理小玩意");
}
Exemplo n.º 3
0
/** Converts IplImage* in to 1-channel to use doCanny().
  Just a convenience function to perform canny detection
  on a 3-channel IplImage*.  The high and low thresholds
  determine the range and sensitivity of edge detection.
  Changing aperture from 3 casues segementation faults.
 */
IplImage* Camera::edgeDetection(IplImage* in, double lowThresh, double highThresh, double aperture){
	// Convert image to grayscale because Canny requires 1-channel
	// Copy to new image so it is a non-destructive change
	IplImage* gray = cvCreateImage( cvGetSize(in), 8, 1);
	cvCvtColor(in, gray, CV_BGR2GRAY);

	gray = doCanny(gray, lowThresh, highThresh, aperture);

	return gray;
}
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
int main( int argc, char* argv[] )
{
	/* Create 3 windows */
	cvNamedWindow( "Exercise_4_1_a_input", CV_WINDOW_AUTOSIZE );
	cvNamedWindow( "Exercise_4_1_a_gray", CV_WINDOW_AUTOSIZE );
	cvNamedWindow( "Exercise_4_1_a_canny", CV_WINDOW_AUTOSIZE );

	g_capture = cvCreateCameraCapture(0);

	IplImage* frame = cvQueryFrame( g_capture );
	IplImage* frameGray = cvCreateImage( 
		cvGetSize(frame), 
		IPL_DEPTH_8U, 
		1);
	IplImage* frameCanny;

	while(1) 
	{
		frame = cvQueryFrame( g_capture );
		if( !frame ) break;
		cvShowImage( "Exercise_4_1_a_input", frame );
		cvCvtColor( frame, frameGray, CV_RGB2GRAY );
		cvShowImage( "Exercise_4_1_a_gray", frameGray );
		frameCanny = doCanny( frame, 10, 150, 3 );
		cvShowImage( "Exercise_4_1_a_canny", frameCanny );
		char c = cvWaitKey(33);
		if( c == 27 ) break;
	}

	/* Cleanup */
	cvReleaseCapture( &g_capture );	
	cvDestroyWindow( "Exercise_4_1_a_canny" );
	cvDestroyWindow( "Exercise_4_1_a_gray" );
	cvDestroyWindow( "Exercise_4_1_a_input" );
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char** argv) {
	cvNamedWindow("Example Gray", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Example Pyr", CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Example Canny", CV_WINDOW_AUTOSIZE);
	IplImage* img_rgb = cvLoadImage(argv[1]);
	IplImage* out;

	out = cvCreateImage(cvSize(img_rgb->width, img_rgb->height),
			img_rgb->depth, 1);
	cvCvtColor(img_rgb, out, CV_BGR2GRAY);
	cvShowImage("Example Gray", out);
	out = doPyrDown(out);
	out = doPyrDown(out);
	cvShowImage("Example Pyr", out);
	out = doCanny(out, 10, 100, 3);
	cvShowImage("Example Canny", out);

	cvWaitKey(0);
	cvReleaseImage(&out);
	cvDestroyWindow("Example Gray");
	cvDestroyWindow("Example Pyr");
	cvDestroyWindow("Example Canny");
	return 0;
}
Exemplo n.º 7
0
void CannyTestWidget::paintGL()
{
	if(m_vi.isFrameNew(0))
	{
		m_vi.getPixels(0, &ucv::gil::view(m_frame)[0][0], true, true);

		doCanny();


		glBindTexture(GL_TEXTURE_2D, m_video_texture);
		glTexSubImage2D(
			GL_TEXTURE_2D,
			0,
			0, 0,
			CANNY_TEST_WIDTH, CANNY_TEST_HEIGHT,
			GL_RGB,
			GL_UNSIGNED_BYTE,
			&ucv::gil::view(m_frame)[0][0]
		);
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	glOrtho(-1, 1, -1, 1, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glDisable(GL_DEPTH_TEST);

	glDisable(GL_NORMALIZE);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glDisable(GL_LIGHTING);
	glShadeModel(GL_SMOOTH);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, m_video_texture);

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glBegin(GL_QUADS) ;
	{
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
	}
	glEnd();

	if(!m_contours.empty())
	{
		glEnable(GL_BLEND);
		glDisable(GL_TEXTURE_2D);
		glLineWidth(1.0f);

		glColor4f(0.0f,1.0f,0.0f,1.0f);
		
		for(std::list<contour_t>::iterator ic=m_contours.begin();ic!=m_contours.end();++ic)
		{
			contour_t &contour=*ic;

			glBegin(GL_LINE_LOOP);
			for(boost::uint32_t cp=0;cp<contour.m_points.size();++cp)
			{
				float const vertex[3]=
				{
					+2.0f*(float(contour.m_points[cp].x())/float(CANNY_TEST_WIDTH)-0.5f),
					-2.0f*(float(contour.m_points[cp].y())/float(CANNY_TEST_HEIGHT)-0.5f),
					0.0f
				};
				glVertex3fv(vertex);
			}
			glEnd();
		}
	}
}