Or is it necessary to use C++ OpenCV?
No, there is no necessity whatsoever. You can use any interface you like and you think you are good with it (OpenCV offers C, C++, Python interfaces).
For your problem about imwrite() and imread() :
For color images the order channel is normally Blue, Green, Red , this is what imshow() , imread() and imwrite() expect
Quoted from there
Answer from Seçkin Savaşçı on Stack OverflowHow to process images of a video, frame by frame, in video streaming using OpenCV and Python - Stack Overflow
OpenCV. How do you catch a real time frame from OpenCV Video Capture - Uncategorized - OpenCV
C++ in Video/Data Processing
[QUESTION] difficulty with simple video processing tutorial
After reading the documentation of VideoCapture. I figured out that you can tell VideoCapture, which frame to process next time we call VideoCapture.read() (or VideoCapture.grab()).
The problem is that when you want to read() a frame which is not ready, the VideoCapture object stuck on that frame and never proceed. So you have to force it to start again from the previous frame.
Here is the code
import cv2
cap = cv2.VideoCapture("./out.mp4")
while not cap.isOpened():
cap = cv2.VideoCapture("./out.mp4")
cv2.waitKey(1000)
print "Wait for the header"
pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
while True:
flag, frame = cap.read()
if flag:
# The frame is ready and already captured
cv2.imshow('video', frame)
pos_frame = cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
print str(pos_frame)+" frames"
else:
# The next frame is not ready, so we try to read it again
cap.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
print "frame is not ready"
# It is better to wait for a while for the next frame to be ready
cv2.waitKey(1000)
if cv2.waitKey(10) == 27:
break
if cap.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
# If the number of captured frames is equal to the total number of frames,
# we stop
break
Use this:
import cv2
cap = cv2.VideoCapture('path to video file')
count = 0
while cap.isOpened():
ret,frame = cap.read()
cv2.imshow('window-name', frame)
cv2.imwrite("frame%d.jpg" % count, frame)
count = count + 1
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows() # destroy all opened windows
I'm going for an interview with a company that does video and data(sensor) processing & analysis. I exclusively have experience in gamedev and was wondering how C++ is typically used in this field? Are there any parallels?
My research has shown me that manual memory management is the number one reason why C++ is used in this industry and I have been brushing up on RAII, move semantics, as well as basics such as references vs pointers, but before I put all my eggs in the wrong basket I wanted to ask here to see if professionals know what type of questions are most likely to come up.
Are there practical uses I can whip out to show that I understand the basics?
Thanks