我写了以下代码:
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)
我在第 18 行中收到错误:(blur = cv2.GaussianBlur(img,(5,5),0))
错误:(-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'cv::Mat::locateROI'
代码之前工作正常,错误突然出现。我尝试将图像扩展名从jpg更改为png,但错误仍然存在。
拉莫斯之舞
相关分类