我正在使用python3和OpenCV等图像处理库开发一个公司徽标图像搜索系统
到目前为止,我已经成功地从给定的图像中提取了单个对象,这些对象被提取为二值图像,因此它们可以很容易地用作遮罩
这是通过K-Means对图像进行聚类,使用具有4向连通性的cv2.connectedComponents
,然后将分水岭应用于分离对象来实现的
# Making a binary version of the kmeans clustered image
gray = cv2.cvtColor(masked_image, cv2.COLOR_BGR2GRAY);
_, binary = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY_INV)
# Euclidean Distance and Distance Mapping
D = ndimage.distance_transform_edt(binary)
localMax = peak_local_max(D, indices = False, min_distance = 25, labels = binary)
# Connected Component Analysis on local peaks and watershed algorithm
markers = ndimage.label(localMax, structure=np.ones((3,3)))[0]
labels = watershed(-D, markers, mask=binary)
print('{} components found'.format(len(np.unique(labels))- 1))
# Loop over unique labels
for label in np.unique(labels):
if label == 0:
continue
# Draw label on the mask
mask = np.zeros(gray.shape, dtype="uint8")
mask[labels == label] = 255
# Detect contours in the mask
cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
# Draw all contours
image = cv2.drawContours(mask, cnts, -1, (0, 255, 0), 1)
cv2_imshow(image)
cv2.imwrite("/content/watershed/contour{}.png".format(label), image)
例如:
输入图像
其中一个输出对象
我现在的目标是在我的数据集中找到包含类似于上面玫瑰的对象(不一定是完全相同的玫瑰)的图像。用R-CNN能做到这一点吗?还有什么其他匹配方法会有用
你有很多选择。我列出了一些想法:
有很多解决方案,您应该尝试其中一些,并将其与验证集进行比较。
希望有帮助
相关问题 更多 >
编程相关推荐