【发布时间】:2018-01-19 19:22:45
【问题描述】:
我是计算机视觉和图像处理的新手,正在使用此代码
from skimage.feature import hog
hog_list, hog_img = hog(test_img_gray,
orientations=8,
pixels_per_cell=(16, 16), cells_per_block=(1, 1),
block_norm='L1',
visualise=True,
feature_vector=True)
plt.figure(figsize=(15,10))
plt.imshow(hog_img)
获取此 HOG 可视化图像
此时我有两个问题:
-
当我尝试保存此图像(作为 .pdf 或 .jpg)时,生成的图像是纯黑色的。将此图像转换为 PIL 格式并使用检查它
hog_img_pil = Image.fromarray(hog_img) hog_img_pil.show()
仍将图像显示为纯黑色。为什么会发生这种情况,我该如何解决?
-
当我尝试运行这段代码时
hog_img = cv2.cvtColor(hog_img, cv2.COLOR_BGR2GRAY)
要将图像转换为灰度,我收到错误error: (-215) depth == CV_8U || depth == CV_16U || depth == CV_32F in function cvtColor。我需要做什么才能让这张图片变成灰度图,为什么会这样?
作为附加信息,运行 hog_img.shape 会返回 (1632, 1224),这只是图像的大小,我最初将其解释为图像已经处于灰度状态(因为它似乎缺少用于颜色通道)。但是,当我尝试运行时
test_img_bw = cv2.adaptiveThreshold(
src=hog_img,
maxValue=255,
adaptiveMethod=cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
thresholdType=cv2.THRESH_BINARY,
blockSize=115, C=4)
我收到错误error: (-215) src.type() == CV_8UC1 in function adaptiveThreshold this 的答案似乎表明图像不是灰度。
最后,还有一点有用的信息是,在图像上运行print(hog_img.dtype) 会返回float64。
在此期间我会继续调试
感谢您的任何想法:)
【问题讨论】:
-
很明显,您的所有问题都是由错误的数据类型引起的。您必须将数据从 float64 转换为算法可以处理的数据。请参阅参考文档和断言错误。
标签: python image opencv computer-vision scikit-image