CaptureData.py 文件源码

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

项目:headlights 作者: Team395 项目源码 文件源码
def diagContour(image):
     #Find contours in the image the first and last returns dont matter so the _ is just a placeholder to ignore them
    _, contours, _ = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    #The contouring operation does some weird stuff to the image so this line just fills the whole thing with black
    image.fill(0)
    boundingRect = []
    firstFail = []
    #Loops through all contours bigger than minArea pixels. That number is tweakable and determined by testing
    for j in [i for i in contours if cv2.contourArea(i) > minArea]:
        #br is a (list/tuple)? of the form x, y, width, height where (x,y) is the (top/bottom)? (left/right)? corner
        br = cv2.boundingRect(j)
        if(abs(br[2]/br[3] - INDASPECT) < indAspectTol and cv2.contourArea(j)/(br[2]*br[3]) > covTol):
            boundingRect.append(br)
        else:
            firstFail.append([br, br[2]/br[3], cv2.contourArea(j)/(br[2]*br[3])])
    secondRound = []
    for x in range(0, len(boundingRect)):
        for y in range(x+1, len(boundingRect)):
            i = boundingRect[x]
            j = boundingRect[y]
            secondRound.append([(x,y,i,j), (abs(i[1]-j[1]), i[3]/2), abs(i[0]-j[0])/i[1]])
    for x in secondRound:
        if(x[1][0] < x[1][1] and x[2] - GRPASPECT < grpAspectTol):
            return [x[0][2], x[0][3]]
        return None;
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号