How to capture an image of a CSI camera in python3?

I am using ridgerun’s IMX708 driver and got it to work no problem.

I want to create a python program that takes pictures and do some stuff with the picture captured. How im currently doing it is on the ridgerun’s guide they have an example pipeline for taking an image, which works and does captures and save the image :

gst-launch-1.0 nvarguscamerasrc num-buffers=1 sensor_id=0 ! 'video/x-raw(memory:NVMM), width=4608, height=2592, framerate=14/1, format=NV12' ! nvjpegenc ! filesink location=image.jpg

I then look for this file in my python script (stripped down):

import os
import time

#capture the image and save it to location
os.system("gst-launch-1.0 nvarguscamerasrc num-buffers=1 sensor_id=0 ! 'video/x-raw(memory:NVMM), width=4608, height=2592, framerate=14/1, format=NV12' ! nvjpegenc ! filesink location=image.jpg")

# Load image 
time.sleep(0.5) # wait for the image to be created
fd = open('image.jpg','rb')
img_str = fd.read()
fd.close()

I do not like this method though as it would create a temporary file somewhere, and i foresee that this has a lot of failure points to protect against

Can anybody point me to guides/show an example of how to capture and image from the csi camera directly inside of python (Specifically python3.7)?

Im currently trying stuff out, for example this code from geeksforgeeks

import cv2 as cv

cam_port = 0
cam = cv.VideoCapture(cam_port) 
  
result, image = cam.read() 
  
if result: 
    cv.imshow("GeeksForGeeks", image) 
    cv.imwrite("GeeksForGeeks.png", image) 
    cv.waitKey(0) 
    cv.destroyWindow("GeeksForGeeks") 

else: 
    print("No image detected. Please! try again")

But no image gets captured

jetson@jetson-desktop:$ sudo python3.7 CameraTest
[ WARN:0@10.824] global cap_v4l.cpp:1134 tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
No image detected. Please! try again

you may refer to… GitHub - JetsonHacksNano/CSI-Camera: Simple example of using a CSI-Camera (like the Raspberry Pi Version 2 camera) with the NVIDIA Jetson Developer Kit

i was able to figure out the problem, it turns out it was my python installation, somehow the openCV installed in 3.7 mess up the original opencv on python 3.6. They dont like eachother. i reverted to only 3.6 with the new flash and everything is working again :)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.