- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这张图片:
我正在尝试用 Python 编写一个函数,如果图像包含蓝色像素,它将返回 True
,否则返回 False
。该图像只是一个例子。如果蓝色可能略有不同,我会有其他人。但它们始终是黑色背景上的蓝色字母。
到目前为止我有这个:
def contains_blue(img):
# Convert the image to HSV colour space
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Define a range for blue color
hsv_l = np.array([100, 150, 0])
hsv_h = np.array([140, 255, 255])
# Find blue pixels in the image
#
# cv2.inRange will create a mask (binary array) where the 1 values
# are blue pixels and 0 values are any other colour out of the blue
# range defined by hsv_l and hsv_h
return 1 in cv2.inRange(hsv, hsv_l, hsv_h)
该函数总是返回 False
,因为在 cv2.inRange
返回的数组中找不到 1
值。也许hsv_l
和hsv_h
定义的范围不好?我是从这里拿来的:OpenCV & Python -- Can't detect blue objects
感谢任何帮助。谢谢。
最佳答案
你可以使用 np.any()
反而。如果任何一个像素的值为 255,它将返回 True
。
所以代替
在 cv2.inRange(hsv, hsv_l, hsv_h) 中返回 1
,
您可以只添加以下内容:
返回 np.any(cv2.inRange(hsv, hsv_l, hsv_h))
更新:
正如@AKX 在评论中提到的,您更愿意尝试以下方法:
返回 cv2.inRange(hsv, hsv_l, hsv_h).any()
关于python - 检查图像是否包含蓝色像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51324202/
我有一个 datagridview,它的唯一目的是显示来自数据库的信息。出于某种原因,我还添加了额外的列,每一行都有“查看”链接。所以基本上 datagridView 的目的只是让用户单击“查看”链接
当按下我的按钮时,我不希望它的外观发生变化。当我触摸它时它会变成蓝色。我尝试进入 IB 并取消选中“突出显示调整图像”,但这似乎没有改变任何东西。我还没有选中“显示高亮显示触摸”。我如何禁用此功能?感
我是 CSS 和一般编程的新手,所以如果这是一个初学者问题,我很抱歉,但我自己找不到合适的解决方案。 如果我有特定的颜色代码(十六进制),例如#028dca,我怎样才能得到匹配的颜色? 我在网上找到了
Fiddler中这个图标是什么意思: 它未在 help 中列出. 最佳答案 此图标用于回复 Content-Type=Content-Type: text/html; 关于fiddler - 蓝色<>
默认的 UIButton 圆角矩形是深蓝色的。我希望表格中单元格的文本与这种蓝色相匹配。 我正在使用此代码,但我能找到的唯一蓝色是亮蓝色... cell.textLabel.textColor = [
我试过这个: myButton.highlight(true) 但这只会使按钮变成深蓝色,这就是按钮的“按下”状态。 此外,当我按键盘上的 Enter 键时,该按钮将不起作用。 当我按下回车键时,如何
我有一个 iOS 6 应用程序,它使用以下方法将所有导航栏按钮的色调颜色设置为绿色: [[UIBarButtonItem appearance] setTintColor:[UIColor color
当我创建一个 TreeView 控件时,插入几个项目,然后我使用 TVM_SELECTITEM 选择一个默认项目。但是这个项目没有用蓝色突出显示。稍后,如果我使用鼠标或键盘选择一个项目,它将突出显示。
目前我有代码: import random from psychopy import visual, event win = visual.Window() # A TextStim and five
如何更改 UISwitch 的默认颜色(蓝色)? 最佳答案 我想你要找的是这样的东西 UISwitch *testSwitch; //just something I made up [testSwi
我有一个 MKMap 和一系列 MKAnnotations,所有这些都是红色的,这很好。我在 IB 中选择了“显示用户位置”并将 MKAnnotation 从红色更改为蓝色,我的 viewForAnn
我正在尝试使用 C++ 和 openCV 检测下图中的 3 个蓝色圆圈。 我用这个代码 int main(){ Mat original=imread("img.jpg"); Ma
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: C# Textbox string separation 我想将字符串值即 (red,blue,black)
我正在使用 cocos2d 库制作 iOS 游戏。 假设您有两个具有两种不同颜色的对象 - 在 RGB 中定义为 Blue: 0,0,255 Yellow: 255,255,0 我想添加蓝色和
有没有办法轻松地将给定的十六进制颜色代码分配给更一般的类别(红色、绿色、蓝色、黄色、橙色、粉色、黑色、白色、灰色……)? 比如 #ffcc55 -> 橙色,#f0f0f0 -> 白色,... 编辑:甚
我创建了一个 UIButton: testNavigationButton.setTitle("Test", forState: .Normal) testNavigationButton.layer
我正在尝试编写一个裸机程序来闪烁绿色 LED。事实上,我无法打开或关闭任何 LED。这是一个现成的板。主板名称为 NUCLEO F429ZI。 Board Image 我已经浏览了原理图,并且确信引脚
我们已经使用对话流创建了一个聊天机器人。现在,我们想要对其进行测试,并需要一些测量或分析数据以确保该机器人已准备好向公众开放。我们使用对话框流中的“分析”功能的方法之一。但是,他们的文档中没有包含任何
我可以在设置 Pane 中更改我的应用程序(任何地方)的tintColor。当我更改tintColor,然后尝试返回到默认色调颜色时,导航栏中的某些按钮不会返回蓝色,我该如何处理这个问题? 验证:-
我希望使用非常明亮的金属色或荧光色来指定我的文本和 div 颜色。我还没有找到显示这些的任何标准。这些是否存在于颜色规范中,或者您能否向我推荐任何接近的尝试。谢谢。 最佳答案 Here's一个很好的荧
我是一名优秀的程序员,十分优秀!