Ask Your Question

Revision history [back]

approx=cv2.approxPolyDP(c,0.02,peri,True) TypeError: integer argument expected, got float

import cv2

import imutils

import pytesseract

pytesseract.pytesseract.tesseract_cmd=r"C:\Program Files\Tesseract- OCR\tesseract.exe"

image =cv2.imread("Image path")

image=imutils.resize(image,width=500)

cv2.imshow("Original Image",image)

cv2.waitKey(0)

gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

cv2.imshow("l - Grayscale convertion",gray)

cv2.waitKey(0)

gray=cv2.bilateralFilter(gray,11,17,17)

cv2.imshow("2-Bilateral Filter",gray)

cv2.waitKey(0)

edged=cv2.Canny(gray,170,200)

cv2.imshow("3-Canny Edge",edged)

cv2.waitKey(0)

cnts,new__=cv2.findContours(edged.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

img1=image.copy()

cv2.drawContours(img1,cnts,-1,(0,255,0),3)

cv2.imshow("4-All Contours",img1)

cv2.waitKey(0)

cnts=sorted(cnts,key=cv2.contourArea,reverse=True)[:30]

NumberPlateCnt=None

img2=image.copy() cv2.drawContours(img2,cnts,-1,(0,255,0),3) cv2.imshow("5-Top 30 Contours",img2) cv2.waitKey(0)

count=0 idx=7 for c in cnts:

peri=cv2.arcLength(c,True) 

print(peri)

approx=cv2.approxPolyDP(c,0.02,peri,True)

if len(approx)==4:
    NumberPlateCnt=approx
    x,y,w,h=cv2.boundingRect(c)
    new_img=image[y:y+h,x:x+w]
    cv2.inwrite("cropped Image-Text/"+str(idx)+'.png',new_img)
    idx+=1       
    break

approx=cv2.approxPolyDP(c,0.02,peri,True) TypeError: integer argument expected, got float

import cv2Code:

import imutils

cv2 import imutils import pytesseract

import pytesseract

pytesseract.pytesseract.tesseract_cmd=r"C:\Program Files\Tesseract- OCR\tesseract.exe"

OCR\tesseract.exe"

image =cv2.imread("Image path")

path") image=imutils.resize(image,width=500) cv2.imshow("Original Image",image) cv2.waitKey(0)

image=imutils.resize(image,width=500)

cv2.imshow("Original Image",image)

cv2.waitKey(0)

gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2.imshow("l - Grayscale convertion",gray)

convertion",gray) cv2.waitKey(0) gray=cv2.bilateralFilter(gray,11,17,17) cv2.imshow("2-Bilateral Filter",gray) cv2.waitKey(0)

cv2.waitKey(0)

edged=cv2.Canny(gray,170,200) cv2.imshow("3-Canny Edge",edged) cv2.waitKey(0) cnts,new__=cv2.findContours(edged.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

gray=cv2.bilateralFilter(gray,11,17,17)

img1=image.copy() cv2.drawContours(img1,cnts,-1,(0,255,0),3) cv2.imshow("4-All Contours",img1) cv2.waitKey(0) cnts=sorted(cnts,key=cv2.contourArea,reverse=True)[:30] NumberPlateCnt=None

cv2.imshow("2-Bilateral Filter",gray)

cv2.waitKey(0)

edged=cv2.Canny(gray,170,200)

cv2.imshow("3-Canny Edge",edged)

cv2.waitKey(0)

cnts,new__=cv2.findContours(edged.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

img1=image.copy()

cv2.drawContours(img1,cnts,-1,(0,255,0),3)

cv2.imshow("4-All Contours",img1)

cv2.waitKey(0)

cnts=sorted(cnts,key=cv2.contourArea,reverse=True)[:30]

NumberPlateCnt=None

img2=image.copy() cv2.drawContours(img2,cnts,-1,(0,255,0),3) cv2.imshow("5-Top 30 Contours",img2) cv2.waitKey(0)

cv2.waitKey(0)

count=0 idx=7 for c in cnts:

cnts:
    peri=cv2.arcLength(c,True) 
    print(f'peri')
    approx=cv2.approxPolyDP(c,0.02,peri,True)   print(peri)

approx=cv2.approxPolyDP(c,0.02,peri,True)

 if len(approx)==4:
     NumberPlateCnt=approx
     x,y,w,h=cv2.boundingRect(c)
     new_img=image[y:y+h,x:x+w]
     cv2.inwrite("cropped Image-Text/"+str(idx)+'.png',new_img)
     idx+=1       
     break