簡體   English   中英

opencv-python:如何識別圖像中的粉紅色木材?

[英]opencv-python: How recognize pink wood in the image?

如何識別圖像中的粉紅色木材 我使用了這個代碼,但我沒有在圖像中找到任何粉紅色的小木頭。

我希望,如果我將這樣的圖像作為輸入,那么粉紅木的 output 將被識別。

除了這個方法,你對識別粉紅色木有什么建議嗎????

輸入:

output 預期(手動標記)

代碼:

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 代碼:

print(contours)
()

問題是無法識別粉紅色的木頭

如下更改您的 HSV 下限和上限:

COLOR_MIN = np.array([130,0,220],np.uint8)    
COLOR_MAX = np.array([170,255,255],np.uint8)  

在此處輸入圖像描述

@nishani-kasineshan 謝謝你的回答。 這就是答案。 一個問題,你為什么選擇這個顏色?

[170,255,255]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM