Ejemplo n.º 1
0
 def __FindHarris(self, filename): #find the corners of images, and save all corner points in self.vKeyPoints
     self.img = highgui.cvLoadImage (filename)
     greyimg = cv.cvCreateImage(cv.cvSize(self.img.width, self.img.height), 8,1)
     w = cv.cvGetSize(self.img).width
     h = cv.cvGetSize(self.img).height
     
     image = cv.cvCreateImage(cv.cvGetSize(self.img), cv.IPL_DEPTH_32F, 1)
     cv.cvConvert(image, greyimg)
     self.cornerimg = cv.cvCreateImage(cv.cvGetSize(self.img), cv.IPL_DEPTH_32F, 1)
     cv.cvCornerHarris(image, self.cornerimg, 11,5,0.1)
Ejemplo n.º 2
0
def returnEllipses(contours):
	ellipses = []
	for c in contours.hrange():
		count = c.total;
		if( count < 6 ):
			continue;
		PointArray = cv.cvCreateMat(1, count, cv.CV_32SC2)
		PointArray2D32f= cv.cvCreateMat( 1, count, cv.CV_32FC2)
		cv.cvCvtSeqToArray(c, PointArray, cv.cvSlice(0, cv.CV_WHOLE_SEQ_END_INDEX));
		cv.cvConvert( PointArray, PointArray2D32f )
		
		box = cv.CvBox2D()
		box = cv.cvFitEllipse2(PointArray2D32f);
		#cv.cvDrawContours(frame, c, cv.CV_RGB(255,255,255), cv.CV_RGB(255,255,255),0,1,8,cv.cvPoint(0,0));

		center = cv.CvPoint()
		size = cv.CvSize()
		center.x = cv.cvRound(box.center.x);
		center.y = cv.cvRound(box.center.y);
		size.width = cv.cvRound(box.size.width*0.5);
		size.height = cv.cvRound(box.size.height*0.5);
		box.angle = -box.angle;
		ellipses.append({'center':center, 'size':size, 'angle':box.angle})
	return ellipses
Ejemplo n.º 3
0
def process_image(slider_pos):
    """
    Define trackbar callback functon. This function find contours,
    draw it and approximate it by ellipses.
    """
    stor = cv.cvCreateMemStorage(0)

    # Threshold the source image. This needful for cv.cvFindContours().
    cv.cvThreshold(image03, image02, slider_pos, 255, cv.CV_THRESH_BINARY)

    # Find all contours.
    nb_contours, cont = cv.cvFindContours(image02, stor, cv.sizeof_CvContour,
                                          cv.CV_RETR_LIST,
                                          cv.CV_CHAIN_APPROX_NONE,
                                          cv.cvPoint(0, 0))

    # Clear images. IPL use.
    cv.cvZero(image02)
    cv.cvZero(image04)

    # This cycle draw all contours and approximate it by ellipses.
    for c in cont.hrange():
        count = c.total
        # This is number point in contour

        # Number point must be more than or equal to 6 (for cv.cvFitEllipse_32f).
        if (count < 6):
            continue

        # Alloc memory for contour point set.
        PointArray = cv.cvCreateMat(1, count, cv.CV_32SC2)
        PointArray2D32f = cv.cvCreateMat(1, count, cv.CV_32FC2)

        # Get contour point set.
        cv.cvCvtSeqToArray(c, PointArray,
                           cv.cvSlice(0, cv.CV_WHOLE_SEQ_END_INDEX))

        # Convert CvPoint set to CvBox2D32f set.
        cv.cvConvert(PointArray, PointArray2D32f)

        box = cv.CvBox2D()

        # Fits ellipse to current contour.
        box = cv.cvFitEllipse2(PointArray2D32f)

        # Draw current contour.
        cv.cvDrawContours(image04, c, cv.CV_RGB(255, 255, 255),
                          cv.CV_RGB(255, 255, 255), 0, 1, 8, cv.cvPoint(0, 0))

        # Convert ellipse data from float to integer representation.
        center = cv.CvPoint()
        size = cv.CvSize()
        center.x = cv.cvRound(box.center.x)
        center.y = cv.cvRound(box.center.y)
        size.width = cv.cvRound(box.size.width * 0.5)
        size.height = cv.cvRound(box.size.height * 0.5)
        box.angle = -box.angle

        # Draw ellipse.
        cv.cvEllipse(image04, center, size, box.angle, 0, 360,
                     cv.CV_RGB(0, 0, 255), 1, cv.CV_AA, 0)

    # Show image. HighGUI use.
    highgui.cvShowImage("Result", image04)
Ejemplo n.º 4
0
def process_image( slider_pos ): 
    """
    Define trackbar callback functon. This function find contours,
    draw it and approximate it by ellipses.
    """
    stor = cv.cvCreateMemStorage(0);
    
    # Threshold the source image. This needful for cv.cvFindContours().
    cv.cvThreshold( image03, image02, slider_pos, 255, cv.CV_THRESH_BINARY );
    
    # Find all contours.
    nb_contours, cont = cv.cvFindContours (image02,
            stor,
            cv.sizeof_CvContour,
            cv.CV_RETR_LIST,
            cv.CV_CHAIN_APPROX_NONE,
            cv.cvPoint (0,0))
    
    # Clear images. IPL use.
    cv.cvZero(image02);
    cv.cvZero(image04);
    
    # This cycle draw all contours and approximate it by ellipses.
    for c in cont.hrange():
        count = c.total; # This is number point in contour

        # Number point must be more than or equal to 6 (for cv.cvFitEllipse_32f).        
        if( count < 6 ):
            continue;
        
        # Alloc memory for contour point set.    
        PointArray = cv.cvCreateMat(1, count, cv.CV_32SC2)
        PointArray2D32f= cv.cvCreateMat( 1, count, cv.CV_32FC2)
        
        # Get contour point set.
        cv.cvCvtSeqToArray(c, PointArray, cv.cvSlice(0, cv.CV_WHOLE_SEQ_END_INDEX));
        
        # Convert CvPoint set to CvBox2D32f set.
        cv.cvConvert( PointArray, PointArray2D32f )
        
        box = cv.CvBox2D()

        # Fits ellipse to current contour.
        box = cv.cvFitEllipse2(PointArray2D32f);
        
        # Draw current contour.
        cv.cvDrawContours(image04, c, cv.CV_RGB(255,255,255), cv.CV_RGB(255,255,255),0,1,8,cv.cvPoint(0,0));
        
        # Convert ellipse data from float to integer representation.
        center = cv.CvPoint()
        size = cv.CvSize()
        center.x = cv.cvRound(box.center.x);
        center.y = cv.cvRound(box.center.y);
        size.width = cv.cvRound(box.size.width*0.5);
        size.height = cv.cvRound(box.size.height*0.5);
        box.angle = -box.angle;
        
        # Draw ellipse.
        cv.cvEllipse(image04, center, size,
                  box.angle, 0, 360,
                  cv.CV_RGB(0,0,255), 1, cv.CV_AA, 0);
    
    # Show image. HighGUI use.
    highgui.cvShowImage( "Result", image04 );