我正在做一个示例任务,我需要突出显示任何移动设备上的异常标记。我正在尝试使用opencv python。但是,我不会因为这些不寻常的标记而得到实际的控制
输入图像如下所示:
我正在尝试下面的方法,但没有成功
import cv2
from matplotlib import pyplot as plt
blurValue = 15
img_path = "input.jpg"
# reading the image
image = cv2.imread(img_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (blurValue, blurValue), 0)
edged = cv2.Canny(image, 100, 255)
#applying closing function
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (7, 7))
closed = cv2.morphologyEx(edged, cv2.MORPH_CLOSE, kernel)
lower = np.array([4, 20, 93])
upper = np.array([83, 79, 166])
# hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# blur = cv2.GaussianBlur(hsv, (blurValue, blurValue), 0)
mask = cv2.inRange(closed, lower, upper)
result_1 = cv2.bitwise_and(frame, frame, mask = mask)
cnts = cv2.findContours(result_1.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
cv2.drawContours(image, [approx], -1, (0, 255, 0), 2)
plt.imshow(image)
plt.title("image")
plt.show()
任何帮助都将不胜感激。多谢各位
我的建议是对面积(可能还有其他特征)使用自适应阈值和过滤器。下面是我使用Python OpenCV的代码和结果
输入:
阈值图像:
形态学处理图像:
最终结果:
我还建议您将图像与已知的干净iPhone图像对齐,并创建相机的遮罩和徽标等标记,以便您可以过滤结果以排除这些标记(甚至可能是相机轮廓的边框)
相关问题 更多 >
编程相关推荐