Android 如何使用OpenCV查找亮绿色激光点?

Android 如何使用OpenCV查找亮绿色激光点?,android,image,opencv,Android,Image,Opencv,android openCV中有检测绿色明亮激光点的代码,但它检测所有的绿色颜色,我只想检测明亮激光,我做了什么我都发布了 如果有任何链接,请让我知道 你的颜色范围不够严格。在下图中,您可以看到我使用的值。圆点周围的圆圈实际上最容易分开。圆点比较硬,因为它包含非常白色的颜色,即饱和度较低的颜色。但是背景也一样,所以用戒指代替。 如果您特别想要圆点,可以使用环的内轮廓 注意:inRange返回一个二进制掩码,因此代码中的这一行不起任何作用: Imgproc.thresholdlowerRedRan

android openCV中有检测绿色明亮激光点的代码,但它检测所有的绿色颜色,我只想检测明亮激光,我做了什么我都发布了

如果有任何链接,请让我知道


你的颜色范围不够严格。在下图中,您可以看到我使用的值。圆点周围的圆圈实际上最容易分开。圆点比较硬,因为它包含非常白色的颜色,即饱和度较低的颜色。但是背景也一样,所以用戒指代替。 如果您特别想要圆点,可以使用环的内轮廓

注意:inRange返回一个二进制掩码,因此代码中的这一行不起任何作用: Imgproc.thresholdlowerRedRange,bw,0,255,Imgproc.threshold_二进制

更新:请求注释中的代码。 带滑块的图片是一个Python脚本,您可以在 带有最终结果的详细图片代码:

import cv2
import numpy as np  
# load image
img = cv2.imread("BPcph.jpg")
# convert to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 
# set lower and upper color limits
lower_val = np.array([58,204,219])
upper_val = np.array([101,255,255])
# Threshold the HSV image 
mask = cv2.inRange(hsv, lower_val, upper_val)
# remove noise
kernel =  np.ones((5,5),np.uint8)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
# find contours in mask
im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# draw contours
for cnt in contours:
    cv2.drawContours(img,[cnt],0,(0,0,255),2)
#show image
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()    

感谢J D的宝贵回复,请分享一些代码,这对meSure非常有帮助,我已经将其添加到了答案中。我使用Python,但它应该很容易转换。谢谢你的回复J.D,你有没有机会帮我在android中提供这段代码?因为我不知道如何使用python,我尝试过,但没有找到任何可以将python转换为android的转换器。感谢函数名是相同的,您已经使用了我使用的几乎所有函数名。如果您不知道如何使用函数,请在中查找。使用您编写的代码逐行替换我的代码,同时查看代码的使用情况。示例:我的代码有np.array,在使用新标量的代码中也是如此。
import cv2
import numpy as np  
# load image
img = cv2.imread("BPcph.jpg")
# convert to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 
# set lower and upper color limits
lower_val = np.array([58,204,219])
upper_val = np.array([101,255,255])
# Threshold the HSV image 
mask = cv2.inRange(hsv, lower_val, upper_val)
# remove noise
kernel =  np.ones((5,5),np.uint8)
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
# find contours in mask
im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# draw contours
for cnt in contours:
    cv2.drawContours(img,[cnt],0,(0,0,255),2)
#show image
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()