我对 OpenCV Python 非常陌生,我真的需要一些帮助。
所以我在这里想做的就是提取下图中的这些单词。
文字和形状都是手绘的,所以并不完美。我在下面做了一些编码。
首先,我对图像进行灰度化
img_final = cv2.imread(file_name)
img2gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
Run Code Online (Sandbox Code Playgroud)
然后我使用 THRESH_INV 显示内容
ret, new_img = cv2.threshold(image_final, 100 , 255, cv2.THRESH_BINARY_INV)
Run Code Online (Sandbox Code Playgroud)
之后,我扩展内容
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3 , 3))
dilated = cv2.dilate(new_img,kernel,iterations = 3)
Run Code Online (Sandbox Code Playgroud)
我放大图像是因为我可以将文本识别为一个簇
之后,我在轮廓周围应用boundingRect并在矩形周围绘制
contours, hierarchy = cv2.findContours(dilated,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) # get contours
index = 0
for contour in contours:
# get rectangle bounding contour
[x,y,w,h] = cv2.boundingRect(contour)
#Don't plot small false positives that aren't text
if w < 10 or h < 10:
continue
# draw rectangle around …
Run Code Online (Sandbox Code Playgroud) 如何检测下面两张图片之间的差异?
我尝试对 2 个图像设置阈值并应用按位异或来查找差异,但仍然无法获得我正在寻找的结果。
图1
图2