I am trying to use python OpenCV to convert Bill's segmented image to white color but have been unsuccessful in doing so. I would essentially like create a white silhouette of Bill in a black background. I have stored the image in a variable called:
bill
Any solutions or direction will be highly appreciated. Thank you
This is the silhouette version of bill when applying the code suggested by frab:
graybill = cv2.cvtColor(bill, cv2.COLOR_BGR2GRAY)
graybill[bill > 0] = 255
The easiest way is:
Convert image to grayscale
graybill = cv2.cvtColor(bill, cv2.COLOR_BGR2GRAY)
Set all values of matrix equal to 255 if the value is greater than 0 (black)
graybill[graybill > 0] = 255
An alternative is to use threshold
from cv2:
ret,thresh1 = cv.threshold(img,1,255,cv.THRESH_BINARY)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.