简体   繁体   English

我现在可以用打开的 cv 检测到蓝色,如果程序检测到蓝色它会打印一些东西,我该如何做到这一点?

[英]I can now detect the colour blue with open cv, How do I make it so now if the program detects blue it prints something?

I'm not really sure how do go about doing this, I think template matching could work but I'm not really sure.我不太确定 go 如何做到这一点,我认为模板匹配可以工作,但我不太确定。 Could someone help?有人可以帮忙吗?

import cv2
import numpy as np

Fishisthere = cv2.imread("FishThere.jpg")

img = Fishisthere[579:600, 850:1360]

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

lowerrange = np.array([106, 147, 0])
upperrange = np.array([179, 255, 245])

mask = cv2.inRange(hsv, lowerrange, upperrange)

cv2.imshow("edited", mask)
#cv2.imshow("normal1", hsv)
#cv2.imshow("normal1", img)

cv2.waitKey(0)
#cv2.destroyAllWindows()

Did u face any errors?你有没有遇到任何错误? When I run ur code, this appears:当我运行你的代码时,会出现:

> Overload resolution failed:
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img'
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img'

I removed the codes on line 6 and it works fine for me:我删除了第 6 行的代码,它对我来说很好用:

import cv2
import numpy as np

Fishisthere = cv2.imread("FishThere.jpg")

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

lowerrange = np.array([106, 147, 0])
upperrange = np.array([179, 255, 245])

mask = cv2.inRange(hsv, lowerrange, upperrange)

cv2.imshow("edited", mask)
#cv2.imshow("normal1", hsv)
#cv2.imshow("normal1", img)

cv2.waitKey(0)
#cv2.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 还是python的新手。 现在很困惑。 如何使该程序正常工作? - Still new to python. So confused right now. How do I make this program work? 如何为Celery进行蓝绿色部署? - How can I do blue green deployment for Celery? 如何将python日期时间设置为相对于现在的(某种程度上)? - How do I set a python datetime to something that is (somewhat) relative to now? 如何将图像蓝盒化? - How can I blue-box an image? “如何修改以下程序,使其以特定格式打印?” - “How can I modify the below program so it prints in a specific format?” 我们如何在Open CV中创建跟踪栏,以便可以使用它跳到视频的特定部分? - How do we create a trackbar in Open CV so that I can use it to skip to specific section of the video? 即使存在不同深浅的蓝色,如何将水的蓝色转换为另一种颜色? - How can I convert the blue color of water into another even if there are different shades of blue present? 我现在如何制作一个GUI来输出结果? - How can I now make a my GUI to output the results? 为什么这个 pygame 程序不起作用,所以当我将鼠标悬停在计算机屏幕上时它会变成蓝色? - Why is this pygame program not working so when I hover over the computer screen it turns blue? 如何在python(JES)中将蓝色最大化为255? - How do i maximize the color blue to 255 in python(JES)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM