[英]opencv-python: How recognize pink wood in the image?
How can I recognize pink wood in an image?如何识别图像中的粉红色木材? I used this code but I did not find any pink small wood in the image.
我使用了这个代码,但我没有在图像中找到任何粉红色的小木头。
I expect that if I give such an image as input, the output of pink wood will be recognized.我希望,如果我将这样的图像作为输入,那么粉红木的 output 将被识别。
Other than this method, do you have a suggestion for recognizing pink wood????除了这个方法,你对识别粉红色木有什么建议吗????
input:输入:
output expected (Manually marked) output 预期(手动标记)
Code:代码:
import numpy as np
import cv2
from cv2 import *
im = cv2.imread(imagePath)
im = cv2.bilateralFilter(im,9,75,75)
im = cv2.fastNlMeansDenoisingColored(im,None,10,10,7,21)
hsv_img = cv2.cvtColor(im, cv2.COLOR_BGR2HSV) # HSV image
COLOR_MIN = np.array([233, 88, 233],np.uint8) # HSV color code lower and upper bounds
COLOR_MAX = np.array([241, 82, 240],np.uint8) # color pink
frame_threshed = cv2.inRange(hsv_img, COLOR_MIN, COLOR_MAX) # Thresholding image
imgray = frame_threshed
ret,thresh = cv2.threshold(frame_threshed,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
print(contours)
for cnt in contours:
x,y,w,h = cv2.boundingRect(cnt)
print(x,y)
cv2.rectangle(im,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imwrite("extracted.jpg", im)
output Code: output 代码:
print(contours)
()
The problem is that pink wood is not recognized问题是无法识别粉红色的木头
@nishani-kasineshan Thank you for your answer. @nishani-kasineshan 谢谢你的回答。 That was the answer.
这就是答案。 One question, why did you choose this color?
一个问题,你为什么选择这个颜色?
[170,255,255]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.