Пример #1
0
def draw_ellipse(image, center, axes, angle,
				 start_angle=0.0, end_angle=360.0,
				 color=(255,0,0), thickness=1):
	center = cv.cvPoint(rnd(center[0]), rnd(center[1]))
	axes = cv.cvSize(rnd(axes[0]), rnd(axes[1]))
	color = cv.CV_RGB(color[0], color[1], color[2])
	cv.cvEllipse(image, center, axes, angle, start_angle, end_angle, color, thickness)  
Пример #2
0
def draw_ellipse(image,
                 center,
                 axes,
                 angle,
                 start_angle=0.0,
                 end_angle=360.0,
                 color=(255, 0, 0),
                 thickness=1):
    center = cv.cvPoint(rnd(center[0]), rnd(center[1]))
    axes = cv.cvSize(rnd(axes[0]), rnd(axes[1]))
    color = cv.CV_RGB(color[0], color[1], color[2])
    cv.cvEllipse(image, center, axes, angle, start_angle, end_angle, color,
                 thickness)
Пример #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)
Пример #4
0
if __name__ == '__main__':

    # create the image where we want to display results
    image = cv.cvCreateImage (cv.cvSize (_SIZE, _SIZE), 8, 1)

    # start with an empty image
    cv.cvSetZero (image)

    # draw the original picture
    for i in range (6):
        dx = (i % 2) * 250 - 30
        dy = (i / 2) * 150
        
        cv.cvEllipse (image,
                      cv.cvPoint (dx + 150, dy + 100),
                      cv.cvSize (100, 70),
                      0, 0, 360, _white, -1, 8, 0)
        cv.cvEllipse (image,
                      cv.cvPoint (dx + 115, dy + 70),
                      cv.cvSize (30, 20),
                      0, 0, 360, _black, -1, 8, 0)
        cv.cvEllipse (image,
                      cv.cvPoint (dx + 185, dy + 70),
                      cv.cvSize (30, 20),
                      0, 0, 360, _black, -1, 8, 0)
        cv.cvEllipse (image,
                      cv.cvPoint (dx + 115, dy + 70),
                      cv.cvSize (15, 15),
                      0, 0, 360, _white, -1, 8, 0)
        cv.cvEllipse (image,
                      cv.cvPoint (dx + 185, dy + 70),
Пример #5
0
                        random_color (random),
                        random.randrange (-1, 9),
                        line_type, 0)
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # draw some ellipes
    for i in range (number):
        pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
                          random.randrange (-height, 2 * height))
        sz = cv.cvSize (random.randrange (0, 200),
                        random.randrange (0, 200))
        angle = random.randrange (0, 1000) * 0.180
        cv.cvEllipse (image, pt1, sz, angle, angle - 100, angle + 200,
                        random_color (random),
                        random.randrange (-1, 9),
                        line_type, 0)
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # init the list of polylines
    nb_polylines = 2
    polylines_size = 3
    pt = [0,] * nb_polylines
    for a in range (nb_polylines):
        pt [a] = [0,] * polylines_size

    # draw some polylines
    for i in range (number):
        for a in range (nb_polylines):
Пример #6
0

if __name__ == '__main__':

    # create the image where we want to display results
    image = cv.cvCreateImage(cv.cvSize(_SIZE, _SIZE), 8, 1)

    # start with an empty image
    cv.cvSetZero(image)

    # draw the original picture
    for i in range(6):
        dx = (i % 2) * 250 - 30
        dy = (i / 2) * 150

        cv.cvEllipse(image, cv.cvPoint(dx + 150, dy + 100), cv.cvSize(100, 70),
                     0, 0, 360, _white, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 115, dy + 70), cv.cvSize(30, 20),
                     0, 0, 360, _black, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 185, dy + 70), cv.cvSize(30, 20),
                     0, 0, 360, _black, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 115, dy + 70), cv.cvSize(15, 15),
                     0, 0, 360, _white, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 185, dy + 70), cv.cvSize(15, 15),
                     0, 0, 360, _white, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 115, dy + 70), cv.cvSize(5, 5), 0,
                     0, 360, _black, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 185, dy + 70), cv.cvSize(5, 5), 0,
                     0, 360, _black, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 150, dy + 100), cv.cvSize(10, 5),
                     0, 0, 360, _black, -1, 8, 0)
        cv.cvEllipse(image, cv.cvPoint(dx + 150, dy + 150), cv.cvSize(40, 10),
Пример #7
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 );
Пример #8
0
                        random_color (random),
                        random.randrange (-1, 9),
                        line_type, 0)
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # draw some ellipes
    for i in range (number):
        pt1 = cv.cvPoint (random.randrange (-width, 2 * width),
                          random.randrange (-height, 2 * height))
        sz = cv.cvSize (random.randrange (0, 200),
                        random.randrange (0, 200))
        angle = random.randrange (0, 1000) * 0.180
        cv.cvEllipse (image, pt1, sz, angle, angle - 100, angle + 200,
                        random_color (random),
                        random.randrange (-1, 9),
                        line_type, 0)
        
        highgui.cvShowImage (window_name, image)
        highgui.cvWaitKey (delay)

    # init the list of polylines
    nb_polylines = 2
    polylines_size = 3
    pt = [0,] * nb_polylines
    for a in range (nb_polylines):
        pt [a] = [0,] * polylines_size

    # draw some polylines
    for i in range (number):
        for a in range (nb_polylines):