【问题标题】:opencv-python: How recognize pink wood in the image?opencv-python:如何识别图像中的粉红色木材?
【发布时间】:2022-01-01 09:44:47
【问题描述】:

如何识别图片中的粉红色木材?我使用了这个代码,但我没有在图像中找到任何粉红色的小木头。

我希望如果我将这样的图像作为输入,pinkwood 的输出将被识别。

除了这个方法,你还有什么识别粉红木的建议???

输入:

预期输出(手动标记)

代码:

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)

输出代码:

print(contours)
()

问题是粉色木头无法识别

【问题讨论】:

  • 输出有什么问题?看起来它找到了我的粉红色木头。
  • 不,输出是手动标记的

标签: python image opencv image-processing computer-vision


【解决方案1】:

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

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

【讨论】:

  • 感谢您的回答。这就是答案。一个问题,你为什么选择这个颜色? [170,255,255]
  • 只玩那些 HSV 范围。正常 HSV 范围:H = 0-360,S = 0-100 和 V = 0-100。 Opencv HSV 范围:H:0-179,S:0-255,V:0-255。不同的应用程序对 HSV 使用不同的尺度。参考类似问题[stackoverflow.com/questions/10948589/…
猜你喜欢
  • 2016-11-15
  • 2020-12-08
  • 1970-01-01
  • 2014-01-16
  • 2017-10-19
  • 2015-07-31
  • 1970-01-01
  • 2021-04-24
  • 1970-01-01
相关资源
最近更新 更多