In VideoCapture class one can only get decoded image, but I want to grab raw jpg data. Grab method seems can do this but the output is only a status flag. Can you kindly add a method that can get the raw data of grab method?
Which version of OpenCV are you using? This functionality was introduced here.
Try this test case to see if it works with your video file.
1 Like
I’m using python opencv version 4.4.0, I tried codes blow but got an error which says im is NoneType.
import cv2
def process(types=cv2.CAP_ANY):
video_url = "test.mp4"
video = cv2.VideoCapture(video_url)
print(video.set(cv2.CAP_PROP_FORMAT, -1))
success, frame = video.read()
print(frame.shape, frame.dtype)
im = cv2.imdecode(frame, cv2.IMREAD_COLOR)
print(im.shape)
cv2.imwrite("a.jpg", im)
if __name__ == "__main__":
process()
retval = cv.imdecode( buf, flags ) is for images, where all the information required for decoding is contained in buf. Your reading from an mp4 where this is not the case (each frame may depend on previous frames + some stream config info which may or may not be present in each frame returned by video.read()) , so I am not surprised that it is not working (maybe it would work with MJPEG).
5 posts were split to a new topic: CAP_PROP_FORMAT -1 (raw) from camera with DSHOW/FFMPEG/windows