Ask Your Question

vegetablejuiceftw's profile - activity

2020-02-07 03:15:44 -0600 received badge  Notable Question (source)
2019-05-19 22:48:14 -0600 received badge  Popular Question (source)
2017-03-16 17:03:26 -0600 received badge  Student (source)
2016-04-25 14:02:16 -0600 received badge  Enthusiast
2016-04-09 19:20:38 -0600 asked a question YUV (bytes) to HSV ?

I have a YUV420p stream from picamera.

I am able to convert it to RGB with this:

def convertYUV(stream,resolution):
fwidth,fheight = resolution
A = np.frombuffer(stream, dtype=np.uint8)
Y = A[:fwidth*fheight]
U = A[fwidth*fheight:fwidth*fheight+(fwidth//2)*(fheight//2)]
V = A[fwidth*fheight+(fwidth//2)*(fheight//2):]
Y = Y.reshape((fheight, fwidth))
U = U.reshape((fheight//2, fwidth//2))
V = V.reshape((fheight//2, fwidth//2))

# lower res to color, raise color to res
# Y = cv2.resize(Y, (fwidth//2,fheight//2), interpolation = cv2.INTER_NEAREST )
U = cv2.resize(U, (fwidth,fheight), interpolation = cv2.INTER_NEAREST )
V = cv2.resize(V, (fwidth,fheight), interpolation = cv2.INTER_NEAREST )
YUV = (np.dstack([Y,U,V])).astype(np.uint8)
RGB = cv2.cvtColor(YUV, cv2.COLOR_YUV2RGB, 3)
# HSV = cv2.cvtColor(RGB, cv2.COLOR_RGB2HSV)
return RGB

and as evident, HSV = cv2.cvtColor(RGB, cv2.COLOR_RGB2HSV), is a simple solution. but the double conversion is too wastefull / slow.

Is there any faster way?

2016-02-26 17:51:40 -0600 received badge  Editor (source)
2016-02-26 17:41:19 -0600 asked a question Raspberry pi camera Y'UV420p to something native (YUV,HSV)?

What would be the fastest way to convert those YUV420p bytes into similar openCV format.

I am doing this for threading or sockets offloading the color tracking.

I am trying to use Unencoded image capture (YUV format) from raspberry pi camera as a raw bytes. (io.BytesIO().geValue()) http://picamera.readthedocs.org/en/re...

Which outputs YUV420 (planar) https://en.wikipedia.org/wiki/YUV#Y.2...

The conversion code seems to exist, but which one of those is it and how do i use it? docs.opencv.org/3.1.0/d7/d1b/group__imgproc__misc.html#ga4e0972be5de079fed4e3a10e24ef5ef0

Currently I am doing it like this, which takes 40ms for camera.resolution = (1024, 512 ) :(

def convertYUV(stream,resolution):

fwidth,fheight = resolution

A = np.frombuffer(stream, dtype=np.uint8)

Y = A[:fwidth*fheight]
U = A[fwidth*fheight:fwidth*fheight+(fwidth//2)*(fheight//2)]
V = A[fwidth*fheight+(fwidth//2)*(fheight//2):]


Y = Y.reshape((fheight, fwidth))
U = U.reshape((fheight//2, fwidth//2))
V = V.reshape((fheight//2, fwidth//2))

# lower res to color or raise color to res
# Y = cv2.resize(Y, (fwidth//2,fheight//2), interpolation = cv2.INTER_NEAREST )
U = cv2.resize(U, (fwidth,fheight), interpolation = cv2.INTER_NEAREST )
V = cv2.resize(V, (fwidth,fheight), interpolation = cv2.INTER_NEAREST )

YUV = (np.dstack([Y,U,V])).astype(np.uint8)

# for testing(saving image) if it is valid YUV
#RGB = cv2.cvtColor(YUV, cv2.COLOR_YUV2RGB, 3)