我尝试过public static class MainClass
{
public static Dictionary<string, Dictionary<string, long>> Dictionaries = new Dictionary<string, Dictionary<string, long>>() {
{ "SubDictionary", new Dictionary<string, long>()
{
{ "property1", 365635},
{ "property2", 156346},
{ "property3", 280847},
}
},
{ "SubDictionary2", new Dictionary<string, long>()
{
{ "property4", 36351526 },
{ "property5", 152415 },
{ "property6", 280114157 },
}
}
};
public static bool FindProperty(string subDictionaryName, IEnumerable<long> list)
{
Dictionary<string, long> dict;
Dictionaries.TryGetValue(subDictionaryName, out dict);
if (dict == null)
{
return false;
}
if (list.Any(i => dict.ContainsValue(i)))
{
return true;
}
else
{
return false;
}
}
}
和FindProperty
,但是这种背面装饰图案给我带来很多麻烦。
我可以尝试其他吗?有任何想法吗?
答案 0 :(得分:0)
这是解决方案的完整代码:
import cv2
import numpy as np
img = cv2.imread('test.png', 0)
img2 = np.zeros_like(img)
cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU,img)
image, contours, hier = cv2.findContours(img, cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
for c in contours:
if cv2.contourArea(c)>50:
cv2.drawContours(img2, c, -1, (255, 255, 255), -1)
kernel = np.ones((40, 10), np.uint8)
img2 = cv2.morphologyEx(img2, cv2.MORPH_CLOSE, kernel)
cv2.imshow("image", img2)
cv2.waitKey(0)
首先,您应该使用cv2.THRESH_BINARY
和cv2.THRESH_OTSU
方法对图像进行二值化。结果将是这样:
之后,您应该消除结果图像中的噪点。为此,我使用cv2.findContours
获取了图像的轮廓,并计算了cv2.contourArea
。然后使用阈值滤除小轮廓,以消除噪声。之后,为了合并侵蚀的字符,我执行了cv2.morphologyEx
。
最终结果是这样的: