如何使用opencv的色相或阈值算法检测种子?

问题描述

我有两个图像。

第一张图片... https://ibb.co/K0NYbZH用于色调

阈值的第二个... ... https://ibb.co/DrPbnH0

第一个问题:我的算法色调算法不起作用。不足以检测和投资回报率.. 第一张图片... https://ibb.co/K0NYbZH用于色调


import cv2
from imutils import contours
import math
import numpy as np
# ilk resim ıcın lınk 
# https://ibb.co/K0NYbZH
image = cv2.imread('basler1.bmp',1)

#image = cv2.resize(image,(512,512))
original = image.copy()
print(original.shape[0]) # 1080
print(original.shape[1]) # 1440


hsv = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)

lower = np.array([34,22,55])
upper = np.array([54,255,255])

mask = cv2.inRange(image,lower,upper )
#res = cv2.bitwise_and(image,image,mask= mask)
cnts = cv2.findContours(mask,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
num = 0

for c in cnts:
    x,y,w,h = cv2.boundingRect(c)
    
    if (math.fabs(w - h) < 2 ) | (math.fabs(x - y) < 2):
        continue
    print(x,h)
    cv2.rectangle(image,(x,y),(x + w,y + h),(136,12),1)

    num += 1
cv2.imshow('image',image)
cv2.imshow('mask',mask)
cv2.waitKey()

或第二选择... 如何最好地使用阈值种子检测进行检测。我的算法不足以检测和roi .. 阈值的第二个İmage... https://ibb.co/DrPbnH0

import cv2
from imutils import contours
import math
# ikinci resim ıcın lınk
# https://ibb.co/DrPbnH0
image = cv2.imread("Basler_acA1440-73gc__40038474__20200417_134730369_0831.tiff")
original = image.copy()
print(original.shape[0]) # 1080
print(original.shape[1]) # 1440

gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
 
thresh = cv2.threshold(gray,cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]

cnts = cv2.findContours(thresh,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
(cnts,_) = contours.sort_contours(cnts,method="left-to-right")
num = 0
for c in cnts:
    x,h = cv2.boundingRect(c)
 
    if (math.fabs(w - h) < 5 ) | (math.fabs(x - y) < 5):
        continue
    print(x,1)
    ROI = original[y:y+h,x:x+w]

    num += 1

cv2.imshow('image',image)
cv2.waitKey()

能帮我谢谢...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...