I have a YUV420_SP_NV21 image represented as a byte array (no headers), taken from an Android preview frame, and I need to decode it into a RGB image. I've done this in Android apps before, using Java and OpenCV4Android:
convert_mYuv = new Mat(height + height / 2, width, CvType.CV_8UC1);
convert_mYuv.put( 0, 0, data );
Imgproc.cvtColor( convert_mYuv, convert_mRgba, type, channels );
I've tried doing the same in Python:
nmp = np.array(byteArray, dtype=np.ubyte)
RGBMatrix = cv2.cvtColor(nmp, cv2.COLOR_YUV420P2RGB)
, but RGBMatrix remains None
.
I'm aware of the possibility to do this myself, I'm familiar with the formula, but would be realy happy to do this the OpenCV way. How can this be done?
I've also tried cv2.imdecode()
, but it failed too, possibly because of me miss-using it.