Ask Your Question

how can I change the video frame in selectROI area from RGB to grayscale? [closed]

asked 2020-02-03 08:54:08 -0500

Kayoh gravatar image

Sorry about bad English :(

I want to change the video frame(videoStream or videoCapture, both) in selectROI area from RGB to grayscale.

I'm using python, and I need help...

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Kayoh
close date 2020-02-04 07:10:54.300834

1 answer

Sort by ยป oldest newest most voted

answered 2020-02-03 10:51:25 -0500

berak gravatar image

updated 2020-02-03 10:55:48 -0500

assuming, your (numpy) frame has 3 channels,

you could copy one of the channels (e.g. green) to make it look grayscale:

# x,y,w,h are selected, get a numpy slice:
roi = frame[y:y+h, x:x+w]

# replace b and r channel in that area with g, so they're all the same:
roi[:,:,0] = roi[:,:,1]
roi[:,:,2] = roi[:,:,1]
edit flag offensive delete link more



It worked for me! Thanks :)

Kayoh gravatar imageKayoh ( 2020-02-03 19:42:01 -0500 )edit

@Kayoh. Why not upvote?

supra56 gravatar imagesupra56 ( 2020-02-03 21:28:24 -0500 )edit

It says '5 points required to upvote'... I'm new to here I'm sorry TT

Kayoh gravatar imageKayoh ( 2020-02-03 21:30:25 -0500 )edit

OIC. I didn't know that.

supra56 gravatar imagesupra56 ( 2020-02-03 22:22:51 -0500 )edit

You can click for close for right answer by you

supra56 gravatar imagesupra56 ( 2020-02-04 07:06:30 -0500 )edit

Question Tools

1 follower


Asked: 2020-02-03 08:54:08 -0500

Seen: 202 times

Last updated: Feb 03 '20