python opencv 图像灰度化,如何在OpenCV(Python)中将灰度图像转换为RGB,以便在处理二进制图像后可视化轮廓?...

在实时应用中学习图像处理时,使用OpenCV进行了阈值处理。将图像从RGB转为灰度,然后想要用绿色标记轮廓,但因为图像为黑白而无法显示。尝试使用`cv2.cvtColor`将灰度图像转换回RGB,但遇到了错误。解决方案包括直接在原始'frame'上绘制轮廓,或者使用正确的`cv2.cvtColor`语法将灰度转换回RGB。
摘要由CSDN通过智能技术生成

I am learning image processing using OpenCV for a realtime application. I did some thresholding on an image and want to label the contours in green, but they aren't showing up in green because my image is in black and white.

Early in the program I used gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) to convert from RGB to grayscale, but to go back I am confused, and the function backtorgb = cv2.cvtColor(gray,cv2.CV_GRAY2RGB) is giving AttributeError: 'module' object has no attribute 'CV_GRAY2RGB'.

The code below does not appear to be drawing contours in green - is this because it's a greyscale image? If so, can I convert the grayscale image back to RGB to visualize the contours in green?

import numpy as np

import cv2

import time

cap = cv2.VideoCapture(0)

while(cap.isOpened()):

ret, frame = cap.rea

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值