dusty-nv / jetson-inference

Hello AI World guide to deploying deep-learning inference networks and deep vision primitives with TensorRT and NVIDIA Jetson.
https://developer.nvidia.com/embedded/twodaystoademo
MIT License
7.71k stars 2.97k forks source link

Failed to power on start and invoke the camera to take photos #1514

Closed wydonglove closed 1 year ago

wydonglove commented 1 year ago

I want to invoke the came to take photos and save when the NX is power on start, i write a start script like this:

#################################### [Unit] Description=Python After=network.service

[Service] Type=simple User=nx Group=nx WorkingDirectory=/home/nx/Ai_project/Pet ExecStart=/usr/bin/python3 /home/nx/Ai_project/Pet/Fetch/detection.py PrivateTmp=true Restart=on-failure

[Install] WantedBy=multi-user.target ####################################

My call camera program function like this: ####################################

def show_camera(save_path,width,hight,rate): #save_path,width,hight,rate) window_title = "CSI Camera" video_capture = cv2.VideoCapture(gstreamer_pipeline(capture_width=width,capture_height=hight,framerate=rate,flip_method=0),cv2.CAP_GSTREAMER)

video_writer = cv2.VideoWriter(
    save_path,
    cv2.VideoWriter_fourcc('m', 'p', '4', 'v'),
    rate,  # fps 每秒的帧数
    (width, hight)  # resolution
)

if video_capture.isOpened():
    try:
        #window_handle = cv2.namedWindow(window_title, cv2.WINDOW_AUTOSIZE)     #必须的
        index = 1
        start_time = time.time()

        while True:
            ret_val, frame = video_capture.read()
            if ret_val:
                video_writer.write(frame)
            else:
                #break
                print(frame)
            index += 1
            if index > 1500:
                break
        print(time.time() - start_time)
    finally:
        video_capture.release()
else:
    print("Error: Unable to open camera")
video_writer.release()

#################################### I can run it right in local , but when i power on start to run script , the video_capture.read() is None , why and how to solve this problem?

dusty-nv commented 1 year ago

Hi @wydonglove, this code is unrelated to jetson-inference - I'd recommend posting this question to the Xavier NX forum instead: https://forums.developer.nvidia.com/c/agx-autonomous-machines/jetson-embedded-systems/jetson-xavier-nx/258