why this code loop forever after a draw a rectangle

meInvent bbird jobmattcon at gmail.com
Fri Sep 16 07:24:49 EDT 2016


im = img.copy()
cntcounter = 0
for cnt in contours:
        epsilon = 0.1*cv2.arcLength(cnt,True)
        approx = cv2.approxPolyDP(cnt,epsilon,True)	
        #peri = cv2.arcLength(cnt, True)
        #approx = cv2.approxPolyDP(c, 0.5 * peri, True)
        #print("len(approx)="+str(len(approx)))
        if len(approx) == 4:
            print("approx=" + str(approx))
            cntcounter = cntcounter + 1
            print("here1")
            x,y,w,h = cv2.boundingRect(cnt)
            print("here2")
            while im is None:
                time.sleep(1)
            if im is not None:                
                print("here3")
                im = cv2.rectangle(im.copy(), (x,y), (x+w, y+h), (0,255,0), 2)                 
                #im = cv2.line(im,(x,y),(x+w,y),(0,255,0),2)
                #im = cv2.line(im,(x+w,y),(x+w,y+h),(0,255,0),2)
                #im = cv2.line(im,(x,y+h),(x+w,y+h),(0,255,0),2)
                #im = cv2.line(im,(x,y),(x,y+h),(0,255,0),2)


cv2.imwrite(r'C:\Users\tester\Documents\masda.png',im)



More information about the Python-list mailing list