How does one convert a grayscale image to RGB in OpenCV (Python) for visualizing contours after processing an image in binary? -


i learning image processing using opencv realtime application. did thresholding on image , want label contours in green, aren't showing in green because image in black , white.

early in program used gray = cv2.cvtcolor(frame, cv2.color_bgr2gray) convert rgb grayscale, go confused, , function backtorgb = cv2.cvtcolor(gray,cv2.cv_gray2rgb) giving attributeerror: 'module' object has no attribute 'cv_gray2rgb'.

the code below not appear drawing contours in green - because it's greyscale image? if so, can convert grayscale image rgb visualize contours in green?

import numpy np import cv2 import time  cap = cv2.videocapture(0) while(cap.isopened()):      ret, frame = cap.read()      gray = cv2.cvtcolor(frame, cv2.color_bgr2gray)      ret, gb = cv2.threshold(gray,128,255,cv2.thresh_binary)      gb = cv2.bitwise_not(gb)      contour,hier = cv2.findcontours(gb,cv2.retr_ccomp,cv2.chain_approx_simple)      cnt in contour:         cv2.drawcontours(gb,[cnt],0,255,-1)     gray = cv2.bitwise_not(gb)      cv2.drawcontours(gray,contour,-1,(0,255,0),3)      cv2.imshow('test', gray)      if cv2.waitkey(1) & 0xff == ord('q'):         break  cap.release() cv2.destroyallwindows() 

i promoting comment answer:

the easy way is:

you draw in original 'frame' instead of using gray image.

the hard way (method trying implement):

backtorgb = cv2.cvtcolor(gray,cv2.color_gray2rgb) correct syntax.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -