Answer the question
In order to leave comments, you need to log in
How to correctly specify the path to the file?
There is a function:
def handle(path, save):
img = cv2.imread(r'C:\progs\ocr3\gdz\form2\ukrainian\ГДЗ Українська мова 2 клас.Н.В Гавриш, Т.С. Маркотенко\numbers\1.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
thresh = 127
im_b = cv2.threshold(img_gray, thresh, 255, cv2.THRESH_BINARY)[1]
contours, hierarchy = cv2.findContours(image = im_b, mode = cv2.RETR_TREE, method = cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key = cv2.contourArea, reverse= True)
mask = np.ones(img.shape[:2], np.uint8)
mask.fill(255)
cv2.drawContours(mask, contours, contourIdx =0 , color =0, thickness = -1)
new_img = cv2.add(im_b, mask)
cv2.imwrite(save,new_img)
img = cv2.imread(r'C:\progs\ocr3\gdz\form2\ukrainian\ГДЗ Українська мова 2 клас.Н.В Гавриш, Т.С. Маркотенко\numbers\1.jpg')
img = cv2.imread(r'C:\progs\ocr3\gdz\form2\ukrainian\1\numbers\1.jpg')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question