Ejemplo n.º 1
0
    if len(conts) != 0:
        biggest = conts[0][2]
        imgWarp = utlis.warpImg(img, biggest, wP, hP)

        imgCont2, conts2 = utlis.getContours(imgWarp,
                                             minArea=2000,
                                             filter=4,
                                             cThr=[50, 50],
                                             draw=False)
        if len(conts) != 0:
            for obj in conts2:
                cv2.polylines(imgCont2, [obj[2]], True, (0, 255, 0), 2)
                nPoints = utlis.reorder(obj[2])
                nW = round(
                    utlis.findDis(nPoints[0][0] // scale,
                                  nPoints[1][0] // scale), 1)
                nH = round(
                    utlis.findDis(nPoints[0][0] // scale,
                                  nPoints[2][0] // scale), 1)
                cv2.arrowedLine(imgCont2, (nPoints[0][0][0], nPoints[0][0][1]),
                                (nPoints[1][0][0], nPoints[1][0][1]),
                                (255, 0, 255), 3, 8, 0, 0.05)
                cv2.arrowedLine(imgCont2, (nPoints[0][0][0], nPoints[0][0][1]),
                                (nPoints[2][0][0], nPoints[2][0][1]),
                                (255, 0, 255), 3, 8, 0, 0.05)
                x, y, w, h = obj[3]
                cv2.putText(imgCont2, '{}mm'.format(nW), (x + 30, y - 10),
                            cv2.FONT_HERSHEY_COMPLEX_SMALL, 1.5, (255, 0, 255),
                            2)
                cv2.putText(imgCont2, '{}mm'.format(nH), (x - 70, y + h // 2),
                            cv2.FONT_HERSHEY_COMPLEX_SMALL, 1.5, (255, 0, 255),
Ejemplo n.º 2
0
    imgContours, conts = utlis.getContours(img, minArea=50000, filter=4)
    if len(conts) != 0:
        biggest = conts[0][2]
        # print(biggest)
        imgWarp = utlis.warpImg(img, biggest, wP, hP)
        imgContours2, conts2 = utlis.getContours(imgWarp,
                                                 minArea=2000,
                                                 filter=4,
                                                 cThr=[50, 50],
                                                 draw=False)

        if len(conts) != 0:
            for obj in conts2:
                cv2.polylines(imgContours2, [obj[2]], True, (0, 255, 0), 2)
                nPoints = utlis.reorder(obj[2])
                nW = round((utlis.findDis(nPoints[0][0] // scale,
                                          nPoints[1][0] // scale) / 10), 1)
                nH = round((utlis.findDis(nPoints[0][0] // scale,
                                          nPoints[2][0] // scale) / 10), 1)
                cv2.arrowedLine(imgContours2,
                                (nPoints[0][0][0], nPoints[0][0][1]),
                                (nPoints[1][0][0], nPoints[1][0][1]),
                                (255, 0, 255), 3, 8, 0, 0.05)
                cv2.arrowedLine(imgContours2,
                                (nPoints[0][0][0], nPoints[0][0][1]),
                                (nPoints[2][0][0], nPoints[2][0][1]),
                                (255, 0, 255), 3, 8, 0, 0.05)
                x, y, w, h = obj[3]
                cv2.putText(imgContours2, '{}cm'.format(nW), (x + 30, y - 10),
                            cv2.FONT_HERSHEY_COMPLEX_SMALL, 1.5, (255, 0, 255),
                            2)
                cv2.putText(imgContours2, '{}cm'.format(nH),