【发布时间】:2018-10-12 15:30:02
【问题描述】:
我有一堆图像,我需要确定十字的位置,以便进一步转换图像和对齐过程。问题是图像非常嘈杂,而且我对计算机视觉的所有这些东西都很陌生。一般来说,我试图通过opencv和python来解决这个任务。我尝试了opencv库教程中描述的几种方法,但没有得到合适的结果。
考虑:我需要确定十字中心的确切位置(我可以手动处理像素精度)。我通过findContours 函数获得的最佳结果。我采用了code from the tutorial,我得到了:
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
import random
random.seed(42)
img = cv.imread("sample.png")
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
img_gray = cv.blur(img_gray, (3,3))
threshold = 150
dst = cv.Canny(img_gray, threshold, threshold * 2)
_, contours, hierarchy = cv.findContours(dst, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
result = np.zeros((dst.shape[0], dst.shape[1], 3), dtype=np.uint8)
for i in range(len(contours)):
color = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256))
cv.drawContours(result, contours, i, color, 2, cv.LINE_8, hierarchy, 0)
cv.imwrite("result.png", result)
fig, ax = plt.subplots()
fig.set_size_inches(10, 10);
ax.imshow(result, interpolation='none', cmap='gray');
导致: 现在我对以下步骤感到困惑。如何定义哪个轮廓是交叉的,哪个不是?如何处理由多个轮廓组成的十字架?
真的很感激任何帮助!
【问题讨论】: