I have written the following code:
import cv2
import lxml.etree as xml
import os
import shutil
for filename in os.listdir(paths['labels']):
with open(paths['labels']+filename,'r'):
img2 = cv2.imread(filename, cv2.IMREAD_COLOR)
# Reading same image in another
# variable and converting to gray scale.
img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
# Converting image to a binary image
# ( black and white only image).
#_, threshold = cv2.threshold(img, 110, 255, cv2.THRESH_BINARY)
blur = cv2.GaussianBlur(img,(5,5),0)
_, threshold = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
# Detecting contours in image.
contours, _= cv2.findContours(threshold, cv2.RETR_TREE, #here it finds the total number of contours, i.e, number of rectangles in the image file
cv2.CHAIN_APPROX_SIMPLE)
I am receiving an Error in the line 18: (blur = cv2.GaussianBlur(img,(5,5),0))
:
Error : (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'cv::Mat::locateROI'
The code was working properly before and error appeared suddenly. I tried changing the image extension from jpg to png but the error remained.