Дальше...Olej писал(а): Начну с видеокамер... Захват камеры и далее чтение происходит как-то так (Python):
Захват видеопотока с камеры и запись его в файл:
Код: Выделить всё
...
cap = cv2.VideoCapture( dev )
...
codec = ( 'DIVX', 'XVID', 'MJPG', 'X264', 'WMV1', 'WMV2' )
ncod = 1 # 1 2 3 4 5 - when choosing a codak, be careful: it must be installed in the system
fourcc = cv2.VideoWriter_fourcc( *codec[ ncod ] ) # Define the codec and create VideoWriter object
fpc = 25
try:
out = cv2.VideoWriter( sys.argv[ 1 ], fourcc, fpc, ( 640, 480 ) )
except Exception as err:
print( "error in output : " + str( err ) )
sys.exit( 1 )
n = 0
while True:
ret, frame = cap.read() # Capture frame-by-frame
if not ret:
break
out.write( frame ) # Write reading frame
cv2.imshow( '', frame ) # Display the resulting frame
n += 1
key = cv2.waitKey( 1 ) & 0xFF
if 27 == key or key == ord( 'q' ): break
cap.release() # When everything done, release the capture
cv2.destroyAllWindows()
out.release()
print( 'saved {} frames'.format( n ) )
Вот что я нашёл где-то в недрах описаний OpenCV:
Но это было в 3.0-beta и потом куда-то исчезло... работает до 3.4.3, после чего ругается, что cv2.VideoWriter_fourcc - неизвестное имя: опять они его куда-то перенесли или переименовали...This time we create a VideoWriter object. We should specify the output file name (eg: output.avi).
Then we should specify the FourCC code (details in next paragraph). Then number of frames per second (fps)
and frame size should be passed. And last one is isColor flag. If it is True, encoder expect color frame,
otherwise it works with grayscale frame.
FourCC is a 4-byte code used to specify the video codec. The list of available codes can be found in fourcc.org.
It is platform dependent. Following codecs works fine for me.
In Fedora: DIVX, XVID, MJPG, X264, WMV1, WMV2. (XVID is more preferable.
MJPG results in high size video. X264 gives very small size video)
In Windows: DIVX (More to be tested and added)
In OSX : (I don’t have access to OSX. Can some one fill this?)
FourCC code is passed as cv2.VideoWriter_fourcc('M','J','P','G') or cv2.VideoWriter_fourcc(*'MJPG) for MJPG.