【发布时间】:2015-07-30 04:59:58
【问题描述】:
我有以下代码:
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from skimage import data
from skimage import filter
from skimage.filter import threshold_otsu
matplotlib.rcParams['font.size'] = 9
nomeimg = 'frame1_depth.png'
i = cv2.imread(nomeimg, -1)
#conversione da 16 a 32 uint
img = np.array(i, dtype=np.uint32)
img *= 65536
print img.dtype
#thresholding con il metodo Otsu
thresh = threshold_otsu(img)
binary = img > thresh
print thresh
plt.figure(1)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
ax1.imshow(img)
ax1.set_title('Original')
ax1.axis('off')
ax2.hist(img)
ax2.set_title('Histogram')
ax2.axvline(x=thresh, color='r', linestyle='dashed', linewidth=2)
ax3.imshow(binary, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')
plt.figure(2)
f, ax = plt.subplots(figsize=(8, 2.5))
ax.imshow(binary, cmap=plt.cm.gray)
ax.set_title('Thresholded')
ax.axis('off')
plt.show()
我有一组来自 XBOX kinect 的深度图像,因此在进行数据类型转换之后,我可以使用一些仅适用于 8 位或 32 位图像的 opencv 函数,我已使用Otsu算法并展示了结果。
我获得了一个子图,其中有我的原始图像、直方图和阈值黑白图像。现在我只想处理这张黑白图像,我想保存它并计算轮廓、凸包和其他几何特征。但是,它只是阈值,但使用otsu。
如何计算?
【问题讨论】:
标签: python opencv image-processing contour