Hello again ,
I have founded a solution in Python but it is pretty slow :
import cv2
from datetime import datetime
import time
def gstreamer_pipeline(
capture_width=3280,
capture_height=2464,
display_width=3280,
display_height=2464,
framerate=21,
flip_method=2,):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
def gstreamer_pipeline2(
capture_width=3280,
capture_height=2464,
display_width=720,
display_height=480,
framerate=21,
flip_method=2,):
return (
"nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), "
"width=(int)%d, height=(int)%d, "
"format=(string)NV12, framerate=(fraction)%d/1 ! "
"nvvidconv flip-method=%d ! "
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! "
"videoconvert ! "
"video/x-raw, format=(string)BGR ! appsink"
% (
capture_width,
capture_height,
framerate,
flip_method,
display_width,
display_height,
)
)
def Take_Picture():
cap2 = cv2.VideoCapture(gstreamer_pipeline2(), cv2.CAP_GSTREAMER)
if cap2.isOpened():
cv2.namedWindow("Picture", cv2.WINDOW_AUTOSIZE)
while cv2.getWindowProperty("Picture", 0) >= 0:
ret2, img2 = cap2.read()
now = datetime.now()
cv2.imshow("Picture", img2)
keyCode = cv2.waitKey(30) & 0xFF
if keyCode == 32:
cap2.release()
cap = cv2.VideoCapture(gstreamer_pipeline(), cv2.CAP_GSTREAMER)
for k in range(0,30):
ret, img = cap.read()
k=k+1
cv2.imwrite(str(now)+".jpg", img)
print("image captured")
cap.release()
cap2 = cv2.VideoCapture(gstreamer_pipeline2(), cv2.CAP_GSTREAMER)
if keyCode == 27:
break
cap.release()
cap2.release()
cv2.destroyAllWindows()
else:
print("Unable to open camera")
if __name__ == "__main__":
Take_Picture()
I open a pipeline to get the preview of the camera and when I want to take a picture :
- I close the preview pipeline
- open a new one with a better resolution
- wait 1 sec for the camera initialise and adjust brightness
- take picture
- close the high resolution pipeline
- open the preview pipeline again.
Does anyone know if there is a better way to do it ?
Thank you very much