def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() #print('Now we start to find the contours in the thresholded image that may be characters:') #if error with expected values: add imgContours to the next line contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour possibleChar = PossibleChar.PossibleChar( contours[i] ) # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour. if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() # imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours contours,npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2:] # find all contours # print("imgContours",imgContours) # print("contours",contours) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for contour in contours: # type(contour) # print(type(contour)) # x,y,w,h=cv2.boundingRect(contour) # print('x,y,w,h',x,y,w,h) #if Main.showSteps == True: #cv2.drawContours(imgThreshCopy, contour, -1, (0, 255, 0), 3) possibleChar = PossibleChar.PossibleChar(contour) x,y,w,h=cv2.boundingRect(contour) # print('x,y,w,h',x,y,w,h) if DetectChars.checkIfPossibleChar(possibleChar): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append(possibleChar) # and add to list of possible chars # print("listOfPossibleChars in findPossibleChars",listOfPossibleChars) # for i in range(0, len(contours)): # for each contour # # if Main.showSteps == True: # show steps ################################################### # # cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # cv2.drawContours(imgThresh, contours, i, Main.SCALAR_WHITE) # # end if # show steps ##################################################################### # # possibleChar = PossibleChar.PossibleChar(contours[i]) # # if DetectChars.checkIfPossibleChar(possibleChar): # if contour is a possible char, note this does not compare to other chars (yet) . . . # intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars # listOfPossibleChars.append(possibleChar) # and add to list of possible chars # # end if # # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if Main.showSteps == True: cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) if Main.showSteps == True: print "\nstep 2 - len(contours) = " + str(len(contours)) print "step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars) cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) #xác định các đường viền đã có height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if Main.showSteps == True: cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) if Main.showSteps == True: print("\nstep 2 - len(contours) = " + str(len(contours))) print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showstep_plate: print("\nstep 2 - len(contours) = " + str(len(contours))) print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() # find all contours imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour. possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour cv2.drawContours(imgContours, contours, i, SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imwrite("./images/2b.png", imgContours) print(intCountOfPossibleChars) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if Main.showSteps == True: cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) # end if # end for if Main.showSteps == True: print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . # kontur olası bir char ise, bu diğer karakterlerle (henüz) karşılaştırılamaz. intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars (olası karakterlerin artış sayısı) listOfPossibleChars.append( possibleChar ) # and add to list of possible chars (ve olası karakterlerin listesine ekle) # end if # end for return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append(possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print "\nstep 2 - len(contours) = " + str(len(contours)) # 2362 with MCLRNF1 image print "step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(img_thresh): possible_chars = [] possible_chars_count = 0 img_thresh_copy = img_thresh.copy() img_contours, contours, npa_hierarchy = cv2.findContours(img_thresh_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = img_thresh.shape img_contours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if Recognitor.showSteps: cv2.drawContours(img_contours, contours, i, Recognitor.SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): possible_chars_count = possible_chars_count + 1 # increment count of possible chars possible_chars.append(possibleChar) # and add to list of possible chars if Recognitor.showSteps: print("\nstep 2 - len(contours) = " + str(len(contours))) print("step 2 - intCountOfPossibleChars = " + str(possible_chars_count)) cv2.imshow("2a", img_contours) return possible_chars
def find_char(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 #Creating a copy of the thresholded image imgThreshCopy = imgThresh.copy() #The following finds all the contours. #To remember contours: https://docs.opencv.org/3.1.0/d4/d73/tutorial_py_contours_begin.html imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) #get height and width of the thresholded image height, width = imgThresh.shape #intializing imgContours = np.zeros((height, width, 3), np.uint8) #loop i from 0 to the number of contours(contours is a list containing the contour's information in each entry, so we get it's length) for i in range(0, len(contours)): #refer to the file PossibleChar.py #it's constructor takes the contour possibleChar = PossibleChar.PossibleChar(contours[i]) #check if the a contour is a possible character. if DetectChars.checkIfPossibleChar(possibleChar): #increment count intCountOfPossibleChars = intCountOfPossibleChars + 1 #add to list of possible chars listOfPossibleChars.append(possibleChar) #When the loop finishes we have a list with all contours having a possibility of being a character. return listOfPossibleChars
def findPossibleCharsInScene(imgThresh, char_aspect_ratio_interval): imgThreshCopy = imgThresh.copy() _, contours, _ = cv2.findContours(imgThreshCopy, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) return [ PossibleChar.PossibleChar(contour) for contour in contours if DetectChars.checkIfPossibleChar( PossibleChar.PossibleChar(contour), char_aspect_ratio_interval) ]
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() #print('Now we start to find the contours in the thresholded image that may be characters:') contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_YELLOW) #cv2.imshow('Thresholded',imgContours) #cv2.waitKey(0) possibleChar = PossibleChar.PossibleChar( contours[i] ) # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour. if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars #cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) #print('This contour may be a character :') #else: #print('This contour is not a character :') # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - Total number of contours found in the image are = " + str(len(contours))) print("step 2 - number of contours those may be characters = " + str(intCountOfPossibleChars)) #print("These are the contours those may be characters :") cv2.imshow("2a", imgContours) cv2.waitKey(0) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] #Dönüş değeri olacak intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # Tüm kontürleri bul SIMPLE ile 4 kontür bulunur height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # Her bir kontür için possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): # Kontur olası bir karakter ise, bunun diğer karakterlerle (henüz) karşılaştırılmadığını unutma intCountOfPossibleChars = intCountOfPossibleChars + 1 # Olası karakterlerin sayısını arttır listOfPossibleChars.append(possibleChar) # Olası listeye ekle return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) return listOfPossibleChars
def get_Possible_Chars_in_input_image(threshold_image): Possible_Chars = [] Possible_Chars_Count = 0 threshold_image_copy = threshold_image.copy() contours, npaHierarchy = cv2.findContours(threshold_image_copy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) for i in range(0, len(contours)): possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): Possible_Chars_Count = Possible_Chars_Count + 1 Possible_Chars.append(possibleChar) return Possible_Chars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() # imgContours, contours = cv2.findContours(imgThreshCopy,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE) # find all contours contours, hierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) #print("---------------------------",imgContours,"---------------------------------------") #print("---------------------------",contours,"---------------------------------------") for i in range(0, len(contours)): # for each contour #print("-----------------------",i) if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar(contours[i]) print( "------------------------------BSK-------------------------------------------" ) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### print(listOfPossibleChars) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [ ] # this will be the return value ##possibleChar intX,intY,intWidth,intHeight爲一組append進去 intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() ##gaussian image here ##cv2.findContours()函数返回两个值,contours是轮廓本身,npaHierarchy是每条轮廓对应的属性。 contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE ) # find all contours ##cv2.RETR_LIST检测的轮廓不建立等级关系 #cv2.CHAIN_APPROX_SIMPLE压缩水平方向,垂直方向,对角线方向的元素,只保留该方向的终点坐标 height, width = imgThresh.shape ##gaussian image imgContours = np.zeros((height, width, 3), np.uint8) ##create black image for i in range(0, len(contours)): # for each contour(輪廓(白點群) if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar( contours[i]) #PossibleChar.py #回傳4個值intX,intY,intWidth,intHeight ##checkIfPossibleChar at DetectChars.py 253 if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . .(去檢測每一個輪廓是否有包含char)##DetectChars函式庫 intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars(有的話intCountOfPossibleChars + 1) listOfPossibleChars.append( possibleChar ) # and add to list of possible chars(把contour[i]的值append進去listOfPossibleChars) # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours cv2.imshow("Thresh",imgThresh) cv2.imshow("imgContours",imgContours - imgThresh) #cv2.imshow("Contours",contours) #object detection and recognition height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) #changed by me-----------------------------------initially 3 ------------------------------------------------------------------- mx = -1; idx = -1; for i in range(0, len(contours)): # for each contour # if Main.showSteps == True: # show steps ################################################### # cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # #end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): # if contour is a possible char, note this does not compare to other chars (yet) . . . cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append(possibleChar) # and add to list of possible chars # end if # end for # if Main.showSteps == True: # show steps ####################################################### # print "\nstep 2 - len(contours) = " + str(len(contours)) # 2362 with MCLRNF1 image # print "step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars) # 131 with MCLRNF1 image # cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene( imgThresh): #用 checkIfPossibleChar() 找到整张图里可能的char listOfPossibleChars = [] imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape for i in range(0, len(contours)): possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): listOfPossibleChars.append(possibleChar) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar( contours[i] ) # Here we calculate the x,y,w,h,flatdiagonalsize,aspedctratio,area and (x,y) of the center of the rectangle that is bounding the contour. if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image imgContours = imutils.resize(imgContours, width=450) cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [ ] #Muhtemel Karakterler Listesi # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) #RETR_LIST ile tüm kenar ve noktalar contoursa atıldı. #bütün kenarlar bulunur. # find all contours height, width = imgThresh.shape #Thresh Resmi şekillendirdik imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: cv2.drawContours( imgContours, contours, i, Main.SCALAR_WHITE ) #imgContours varolan noktalar ve kenarlar beyazlatıldı. possibleChar = PossibleChar.PossibleChar( contours[i] ) # contours her kenar for ile dönerek muhtemelCharlara tanımlandı. if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars #Muhtemel karakter geldiğinde artış sayısı listOfPossibleChars.append( possibleChar) # and add to list of possible chars #Karakterin listeye eklenmesi if Main.showSteps == True: print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours # two line will show all contours in black image height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # All contours in white # end if # show steps ##################################################################### # This step will initialize all values of constructor like width,height,aspect ratio,diagonal,centre x and y etc possibleChar = PossibleChar.PossibleChar(contours[i]) # Note: possibleChar is object of class PossibleChar if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 with MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 with MCLRNF1 image cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): possibleChars = [] possibleCharsCount = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): possibleCharsCount = possibleCharsCount + 1 possibleChars.append(possibleChar) return possibleChars
def findPossibleCharsInScene(imgThresh): # Valor a ser retornado listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if Main.showSteps: cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if possibleChar = PossibleChar.PossibleChar(contours[i]) # Verifica se o contorno é um possível caracter if DetectChars.checkIfPossibleChar(possibleChar): # Incrementa contado intCountOfPossibleChars += 1 # Adiciona na lista listOfPossibleChars.append(possibleChar) # end if # end for if Main.showSteps: print "\nstep 2 - len(contours) = " + str(len(contours)) print "step 2 - intCountOfPossibleChars = " + str( intCountOfPossibleChars) cv2.imshow("2a", imgContours) # end if return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # este será el valor de retorno intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # encontrar todos los contornos height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # para cada contorno if Main.showSteps == True: # mostrar pasos cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # mostrar pasos possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar ): # if contour is a possible char, note this does not compare to other chars (yet) . . . intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) # 2362 con MCLRNF1 image print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) # 131 con MCLRNF1 image cv2.imshow("2a", imgContours) # end if # mostar pasos return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): # Matrica koja očekuje moguće znakove listOfPossibleChars = [] # Varijabla koja broji potencijalne znakove intCountOfPossibleChars = 0 # Kopija matrice imgTresh sa tresholdanom slikom imgThreshCopy = imgThresh.copy() # -------------------------------------------- KONTURE -------------------------------------------------------------------- # CV funkcija imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # Određivanje visine i širine slike height, width = imgThresh.shape # Prazna matrica imgContours = np.zeros((height, width, 3), np.uint8) # FOR petlja koja prolazi kroz sve moguce kontura # Broj kontura definiran ranije korištenjem CV funckije findContours for i in range(0, len(contours)): # Šalje svaku konturu na pregled, je li možda znak possibleChar = PossibleChar.PossibleChar(contours[i]) # PROMJENA # Dobije se veličina, OMJER konture (podaci o konturi) # Pozivanje funckije checkIfPossibleChar iz skripte DetectChars, kojoj predajem varijablu possibleChar if DetectChars.checkIfPossibleChar(possibleChar): # PROMJENA # GLeda je li kontura dovoljne, definirane veličine koja je znak # DOBRA KONTURA - MOGUCI ZNAK # Ukoliko je kontora dobra, povećava se gore navedena varijbal koja broji moguce znakove intCountOfPossibleChars = intCountOfPossibleChars + 1 # Untar gore deklariranog niza, appenda se kontura, odnosno moguci znak .....DA listOfPossibleChars.append(possibleChar) # Lista kontura koji su moguci znakovi return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() imgContours, contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour if Main.showSteps == True: # show steps ################################################### cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # end if # show steps ##################################################################### possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 # increment count of possible chars listOfPossibleChars.append( possibleChar) # and add to list of possible chars # end if # end for if Main.showSteps == True: # show steps ####################################################### print("\nstep 2 - len(contours) = " + str(len(contours))) print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) cv2.imshow("2a", imgContours) # end if # show steps ######################################################################### return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # khởi danh sách có thể là kí tự intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE ) # tìm tất cả các đường viền có thể có trong ảnh xám height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # với mỗi đường viền if Main.showSteps == True: cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE) # vẽ đường viền(contour) # end if possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar( possibleChar): # nếu đường viền có thể là kí tự intCountOfPossibleChars = intCountOfPossibleChars + 1 # tăng thêm lượt đém listOfPossibleChars.append(possibleChar) # thêm vào danh sách # end if # end for if Main.showSteps == True: print("\nstep 2 - len(contours) = " + str(len(contours))) print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars)) cv2.imshow("2a", imgContours) # end if return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): if LicensePlateRecognition.showSteps == True: cv2.drawContours(imgContours, contours, i, LicensePlateRecognition.SCALAR_WHITE) possibleChar = PossibleChar.PossibleChar(contours[i]) if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + 1 listOfPossibleChars.append(possibleChar) if LicensePlateRecognition.showSteps == True: print("step 2 - ", end="") print((len(contours)), end="") print(" = ", end="") print(str(len(contours))) print("step 2 - ", end="") print(intCountOfPossibleChars, end=" ") print(" = ", end="") print(str(intCountOfPossibleChars)) cv2.imshow("2a", imgContours) return listOfPossibleChars
def findPossibleCharsInScene(imgThresh): listOfPossibleChars = [] # this will be the return value intCountOfPossibleChars = 0 imgThreshCopy = imgThresh.copy() contours, npaHierarchy = cv2.findContours( imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours height, width = imgThresh.shape imgContours = np.zeros((height, width, 3), np.uint8) for i in range(0, len(contours)): # for each contour possibleChar = PossibleChar.PossibleChar(contours[i]) # if contour is a possible char, note this does not compare to other chars (yet) . . . if DetectChars.checkIfPossibleChar(possibleChar): intCountOfPossibleChars = intCountOfPossibleChars + \ 1 # increment count of possible chars # and add to list of possible chars listOfPossibleChars.append(possibleChar) return listOfPossibleChars