材料检测

2024-05-17 05:27:28 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我正在检测如下材料:

enter image description here

我试着检测棕色晶体,做圆形检测或矩形检测,但还是有很多噪音

我试着使用hsv如下:

canny = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower_red = np.array([15,10,50])
upper_red = np.array([150,110,160])
edged = cv2.inRange(canny, lower_red, upper_red)

。。。或者用这个。但没人帮忙。你知道吗

imgray= cv2.GaussianBlur(imgray, (7,7),0)
ret, thresh = cv2.threshold(imgray, 237, 28, 37)
edged = cv2.Canny(imgray, 5, 5)
edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)

有什么我能做的吗?你知道吗

谢谢


Tags: nonenpred圆形arraycv2upperlower
1条回答
网友
1楼 · 发布于 2024-05-17 05:27:28

我想你要找的是一个近距离的手术。你知道吗

from PIL import Image
import cv2
import matplotlib.pyplot as plt

img = Image.open('./n2JCm.png')

img_np = np.array(img)

img_np_rgb = cv2.cvtColor(AA,cv2.COLOR_RGBA2RGB)

plt.figure(figsize=(35,35))
plt.imshow(cv2.morphologyEx(img_np_rgb,cv2.MORPH_CLOSE,np.ones((2,2)),iterations=10))

你会得到这样的结果: enter image description here

那会把你身上的小污点去掉的。你知道吗

我也会尝试使用KMeans或DBScan进行集群

from sklearn import cluster

model = cluster.KMeans(3)

plt.figure(figsize=(35,35))
plt.imshow(model.fit_predict(img_np_rgb.reshape((-1,3))).reshape(img_np_rgb.shape[:2]))

enter image description here

或者其他聚类算法。你知道吗

相关问题 更多 >