【发布时间】:2020-03-06 20:21:39
【问题描述】:
我正在尝试使用 Haar 级联分类器进行对象检测。我已经复制了 haar 级联算法的代码,但它不起作用。它给出的错误为 未知的网址类型:'//drive.google.com/drive/folders/11XfAPOgFv7qJbdUdPpHKy8pt6aItGvyg' 即使此链接有效。
导入 urllib.request、urllib.error、urllib.parse 导入cv2
导入操作系统
def store_raw_images():
neg_images_link = '//drive.google.com/drive/folders/11XfAPOgFv7qJbdUdPpHKy8pt6aItGvyg'
neg_image_urls = urllib.request.urlopen(neg_images_link).read().decode()
pic_num = 1
if not os.path.exists('neg'):
os.makedirs('neg')
for i in neg_image_urls.split('\n'):
try:
print(i)
urllib.request.urlretrieve(i, "neg/"+str(pic_num)+".jpg")
img = cv2.imread("neg/"+str(pic_num)+".jpg",cv2.IMREAD_GRAYSCALE)
# should be larger than samples / pos pic (so we can place our image on it)
resized_image = cv2.resize(img, (100, 100))
cv2.imwrite("neg/"+str(pic_num)+".jpg",resized_image)
pic_num += 1
except Exception as e:
print(str(e))
store_raw_images()
我期望输出为一组负图像,用于创建用于对象检测的数据集模块。
【问题讨论】: