Esempio n. 1
0
    def redraw(self):

        edge_img = cv.Mat()
        # 边缘检测
        cv.Canny(self.img_gray, edge_img, self.th1, self.th2)
        3  ###
        # 计算结果图
        if self.show_canny:
            show_img = cv.Mat()
            cv.cvtColor(edge_img, show_img, cv.CV_GRAY2BGR)
        else:
            show_img = self.img.clone()
        4  ###
        # 线段检测
        theta = self.theta / 180.0 * np.pi
        lines = cv.HoughLinesP(edge_img, self.rho, theta, self.hough_th,
                               self.minlen, self.maxgap)
        for line in lines:
            cv.line(show_img, cv.asPoint(line[:2]), cv.asPoint(line[2:]),
                    cv.CV_RGB(255, 0, 0), 2)
        5  ###
        # 圆形检测
        circles = cv.HoughCircles(self.img_smooth,
                                  3,
                                  self.dp,
                                  self.mindist,
                                  param1=self.param1,
                                  param2=self.param2)

        for circle in circles:
            cv.circle(show_img, cv.Point(int(circle[0]), int(circle[1])),
                      int(circle[2]), cv.CV_RGB(0, 255, 0), 2)

        cv.imshow("Hough Demo", show_img)
Esempio n. 2
0
def mouse_call_back(event, x, y, flags, user_data):
    global seed

    # 右键松开时,初始化种子图像
    if event == cv.CV_EVENT_RBUTTONUP:
        img2[:] = img[:]
        markers[:] = 0
        seed = 1
        cv.imshow("Watershed Demo", img2)

    if seed == len(marks_color): return

    # 左键按下时,在种子图像上添加种子
    if flags == cv.CV_EVENT_FLAG_LBUTTON:
        pt = cv.Point(x, y)
        cv.circle(markers, pt, 5, cv.Scalar(seed, seed, seed, seed),
                  cv.CV_FILLED)
        cv.circle(img2, pt, 5, marks_color[seed], cv.CV_FILLED)
        cv.imshow("Watershed Demo", img2)

    # 左键松开时,使用watershed进行图像分割
    if event == cv.CV_EVENT_LBUTTONUP:
        seed += 1
        tmp_markers = markers.clone()
        cv.watershed(img, tmp_markers)
        color_map = tmp_markers[:].astype(np.int)

        img3 = img2.clone()
        img4 = cv.asMat(palette[color_map])
        cv.addWeighted(img3, 1.0, img4, mask_opacity, 0, img3)
        cv.imshow("Watershed Demo", img3)
def mouse_call_back(event, x, y, flags, user_data):
    global seed
    
    # 右键松开时,初始化种子图像
    if event == cv.CV_EVENT_RBUTTONUP: 
        img2[:] = img[:]    
        markers[:] = 0
        seed = 1
        cv.imshow("Watershed Demo", img2)
        
    if seed == len(marks_color): return
    
    # 左键按下时,在种子图像上添加种子
    if flags == cv.CV_EVENT_FLAG_LBUTTON: 
        pt = cv.Point(x, y)
        cv.circle(markers, pt, 5, cv.Scalar(seed,seed,seed,seed), cv.CV_FILLED)
        cv.circle(img2, pt, 5, marks_color[seed], cv.CV_FILLED)
        cv.imshow("Watershed Demo", img2)
        
    # 左键松开时,使用watershed进行图像分割
    if event == cv.CV_EVENT_LBUTTONUP:  
        seed += 1
        tmp_markers = markers.clone() 
        cv.watershed(img, tmp_markers)
        color_map = tmp_markers[:].astype(np.int) 
        
        img3 = img2.clone()
        img4 = cv.asMat( palette[color_map] ) 
        cv.addWeighted(img3, 1.0, img4, mask_opacity, 0, img3) 
        cv.imshow("Watershed Demo", img3)
 def redraw(self):
     
     edge_img = cv.Mat()
     # 边缘检测
     cv.Canny(self.img_gray, edge_img, self.th1, self.th2)
     3###
     # 计算结果图
     if self.show_canny: 
         show_img = cv.Mat()
         cv.cvtColor(edge_img, show_img, cv.CV_GRAY2BGR)
     else:
         show_img = self.img.clone()
     4### 
     # 线段检测   
     theta = self.theta / 180.0 * np.pi
     lines = cv.HoughLinesP(edge_img,  
         self.rho, theta, self.hough_th, self.minlen, self.maxgap)
     for line in lines: 
         cv.line(show_img, 
             cv.asPoint(line[:2]),  
             cv.asPoint(line[2:]),
             cv.CV_RGB(255, 0, 0), 2)
     5###
     # 圆形检测
     circles = cv.HoughCircles(self.img_smooth, 3,  
         self.dp, self.mindist, param1=self.param1, param2=self.param2)
         
     for circle in circles: 
         cv.circle(show_img, 
             cv.Point(int(circle[0]), int(circle[1])), int(circle[2]), 
             cv.CV_RGB(0, 255, 0), 2)
     
     cv.imshow("Hough Demo", show_img)
 def painter_updated(self):
     for _, _, x, y in self.painter.track:
         # 在储存选区的mask上绘制圆形
         cv.circle(self.mask, cv.Point(int(x), int(y)), int(self.painter.r), 
             cv.Scalar(255,255,255,255), thickness=-1) # 宽度为负表示填充圆形
     self.inpaint()
     self.painter.track = []
     self.painter.request_redraw()
Esempio n. 6
0
def draw_circle(src, center, radius, color=(255.0, 0, 0), thickness=1):

    if isinstance(center, tuple):
        center = new_point(*center)
    cv.circle(src, center, radius,
              convert_color(color),
              thickness=thickness,
              lineType=cv.CV_AA
              )
Esempio n. 7
0
def draw_point(src, pt, color=(255, 0, 0), thickness= -1):
    '''
    '''
    if isinstance(pt, (tuple, list)):
#        pt = [int(pi for pi in pt]
        pt = cv.Point2d(*pt)

    color = convert_color(color)
    cv.circle(src, pt, 5, color, thickness=thickness)
Esempio n. 8
0
 def painter_updated(self):
     for _, _, x, y in self.painter.track:
         # 在储存选区的mask上绘制圆形
         cv.circle(self.mask,
                   cv.Point(int(x), int(y)),
                   int(self.painter.r),
                   cv.Scalar(255, 255, 255, 255),
                   thickness=-1)  # 宽度为负表示填充圆形
     self.inpaint()
     self.painter.track = []
     self.painter.request_redraw()
Esempio n. 9
0
 def draw_keypoints(self, img, keypoints, offset):
     for kp in keypoints:
         center = cv.Point(int(kp.pt.x) + offset, int(kp.pt.y))
         cv.circle(img, center, int(kp.size * 0.25), cv.CV_RGB(255, 255, 0))
Esempio n. 10
0
    correspond[:object.rows, :object.cols] = object[:]
    correspond[object.rows:, :image.cols] = image[:]

    # find pairs
    ptpairs = findPairs(surf, objectKeypoints, objectDescriptors,
                        imageKeypoints, imageDescriptors)

    for pair in ptpairs:
        cv.line(correspond, cv.asPoint(pair[0]),
                cv.Point(int(pair[1].x), int(pair[1].y + object.rows)),
                colors[8])

    # locate planar object
    if locatePlanarObject(ptpairs, src_corners, dst_corners):
        for i in range(4):
            r1 = dst_corners[i]
            r2 = dst_corners[(i + 1) % 4]
            cv.line(correspond, cv.Point(r1.x, r1.y + object.rows),
                    cv.Point(r2.x, r2.y + object.rows), colors[8])

    # show the object correspondents
    cv.imshow("Object Correspond", correspond)

    # draw circles
    for keypt in objectKeypoints:
        cv.circle(object_color, cv.asPoint(keypt.pt),
                  int(keypt.size * 1.2 / 9. * 2), colors[0], 1, 8, 0)
    cv.imshow("Object", object_color)

    cv.waitKey(0)
 def draw_keypoints(self, img, keypoints, offset):
     for kp in keypoints:
         center = cv.Point(int(kp.pt.x)+offset, int(kp.pt.y))
         cv.circle(img, center, int(kp.size*0.25), cv.CV_RGB(255,255,0))
Esempio n. 12
0
    # create a correspond Mat
    correspond = cv.Mat(image.rows+object.rows, image.cols, cv.CV_8UC1, cv.Scalar(0))
    
    # copy the images to correspond -- numpy way
    correspond[:object.rows, :object.cols] = object[:]
    correspond[object.rows:, :image.cols] = image[:]

    # find pairs
    ptpairs = findPairs(surf, objectKeypoints, objectDescriptors, imageKeypoints, imageDescriptors)

    for pair in ptpairs:
        cv.line( correspond, cv.asPoint(pair[0]), cv.Point(int(pair[1].x), int(pair[1].y+object.rows)), colors[8] )

    # locate planar object
    if locatePlanarObject( ptpairs, src_corners, dst_corners ):
        for i in range(4):
            r1 = dst_corners[i]
            r2 = dst_corners[(i+1)%4]
            cv.line( correspond, cv.Point(r1.x, r1.y+object.rows ), cv.Point(r2.x, r2.y+object.rows ), colors[8] )

    # show the object correspondents
    cv.imshow("Object Correspond", correspond)
    
    # draw circles
    for keypt in objectKeypoints:
        cv.circle(object_color, cv.asPoint(keypt.pt), int(keypt.size*1.2/9.*2), colors[0], 1, 8, 0)
    cv.imshow("Object", object_color)
        
    cv.waitKey(0)