コード例 #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)
コード例 #2
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)
コード例 #3
0
ファイル: find_obj.py プロジェクト: uniquerobot/pyopencv
    print("Extraction time = %gms\n" % (tt / (cv.getTickFrequency() * 1000.)))

    # 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
コード例 #4
0
ファイル: find_obj.py プロジェクト: BackupGGCode/pyopencv
    print("Image Descriptors: %d\n" % len(imageKeypoints))
    tt = float(cv.getTickCount()) - tt
    print("Extraction time = %gms\n" % (tt/(cv.getTickFrequency()*1000.)))
    
    # 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)