python - OpenCV python使用阈值搜索颜色
问题描述
我正在尝试按以下方式组合两个图像。我有这两个图像 一个文件夹和封面图像,结合这两个图像我想得到这个最终结果。为此,我执行以下操作。
import cv2
import numpy as np
img = cv2.imread('carpeta3.png', cv2.IMREAD_UNCHANGED)
cover = cv2.imread('cover.png', cv2.IMREAD_UNCHANGED)
pos = np.full((img.shape[0],img.shape[1]), False)
#Search for green pixels
for i in range (0,img.shape[0]):
for j in range (0,img.shape[1]):
color = img[i,j]
if color[0] == 0 and color[1] == 255 and color[2] == 0:
pos[i,j] = True
else:
continue
#cropping the cover image
for i in range (0,img.shape[0]):
for j in range (0,img.shape[1]):
if pos[i,j] == False:
cover[i,j] = [0,0,0,255]
else:
continue
#combining the two images
for i in range (0,img.shape[0]):
for j in range (0,img.shape[1]):
if pos[i,j] == True:
img[i,j] = cover[i,j]
else:
continue
cv2.imwrite('D:/Img/test.png',img)
作为最终结果,我在执行代码后得到了这个最终结果 。如您所见,还剩下一些绿色像素,有没有办法用阈值搜索这些像素?
解决方案
推荐阅读
- javascript - document.getElementById 不能选择多个元素
- php - 需要帮助改写两行代码,因为.eregi_replace 已被贬低
- java - 如何从源代码创建输出 JAVA 包?
- javascript - 很难理解 gridfs 和连接
- python - 在文本中查找单词,非常慢的解决方案
- azure-devops - AppCenter在构建时找不到私有包
- python - google colab [google-colaboratory] 中的 conda 环境
- php - Artisan migrate 因(非常)大量数据插入而失败
- audio-streaming - 仅从 10 厘米处检测音频。仅当人说 android 时才流式传输音频
- python - 在张量流中构建自定义损失函数时遇到问题