#NEWLINE# def is_square( contour ) : #NEWLINE# #INDENT# peri = cv2 . arcLength ( contour , True ) #NEWLINE# approx = cv2 . approxPolyDP ( contour , ( 0.02 * peri ) , True ) #NEWLINE# if ( ( len ( approx ) >= 4 ) and ( len ( approx ) <= 6 ) ) : #NEWLINE# #INDENT# ( x , y , w , h ) = cv2 . boundingRect ( approx ) #NEWLINE# aspectRatio = ( w / float ( h ) ) #NEWLINE# area = cv2 . contourArea ( contour ) #NEWLINE# hullArea = cv2 . contourArea ( cv2 . convexHull ( contour ) ) #NEWLINE# solidity = ( area / float ( hullArea ) ) #NEWLINE# keepSolidity = ( solidity > 0.9 ) #NEWLINE# keepAspectRatio = ( ( aspectRatio >= 0.8 ) and ( aspectRatio <= 1.2 ) ) #NEWLINE# keepSize = ( cv2 . arcLength ( contour , True ) > 60 ) #NEWLINE# if ( keepSolidity and keepAspectRatio and keepSize ) : #NEWLINE# #INDENT# return True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False