arch_light_track.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Vision_Processing-2016 作者: Sabercat-Robotics-4146-FRC 项目源码 文件源码
def get_bounding_rect( cap, win_cap, win, upper, lower):
    msk = cv2.dilate(cv2.erode( cv2.inRange( cv2.blur( cv2.cvtColor( cap, cv2.COLOR_BGR2HSV ), (5,5) ), np.array(lower), np.array(upper) ), None, iterations=3), None, iterations=3)
    im2, contours, hierarchy = cv2.findContours( msk, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE )
    if len(contours) > 0:
        areas = [cv2.contourArea(c) for c in contours] # get the area of each contour
        max_index = np.argmax(areas) # get the index of the largest contour by area
        cnts = contours[max_index] # get the largest contout by area
        cv2.drawContours(msk, [cnts], 0, (0,255,0), 3) # Draw the contours to the mask image
        x,y,w,h = cv2.boundingRect(cnts) #  get the bouding box information about the contour
        cv2.rectangle(win_cap,(x,y),(x+w,y+h),(255,255,255),2) # Draw rectangle on the image to represent the bounding box
        cv2.imshow( "debug.", win_cap )
        try:
            self.smt_dash.putNumber('vis_x', x)
            self.smt_dash.putNumber('vis_y', y)
            self.smt_dash.putNumber('vis_w', w)
            self.smt_dash.putNumber('vis_h', h)
        except Exception:
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号