I'm working on a project where I have to apply threshold to a YUV420_SP_NV21 image (taken from an Android camera) to determine which pixels are 'black' and which are 'white'.
Therefore, I want to import it in Python as a bytearray (using OpenCV, NumPy, PIL, ...), so I can do some quick bitwise operations on the Y-values.
However, when I try to import the image using the following methods, I get useless outputs:
When I type
import cv2
import numpy as np
img = cv2.imread('test.yuv')
imgArr = np.array(img)
print(img)
print(imgArr)
I get as output:
None
None
And when I type
import numpy as np
f = open('test.yuv', 'rb')
img = f.read()
imgArr = np.array(img)
I get some useless character sequence.
And when I type now (for exemple)
print(imgArr[0])
I get as output:
IndexError: too many indices for array
Which means imgArr is no array at all!
Can anyone please tell me what I'm doing wrong?
Thanks in advance!