Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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/release-1.10/recipes2.html#unencoded-image-capture-yuv-format

Which outputs YUV420 (planar) https://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12_or_YV12.29_to_RGB888_conversion

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)

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/release-1.10/recipes2.html#unencoded-image-capture-yuv-format

Which outputs YUV420 (planar) https://en.wikipedia.org/wiki/YUV#Y.27UV420p_.28and_Y.27V12_or_YV12.29_to_RGB888_conversion

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)