메뉴 건너뛰기

XEDITION

Jetson

JetsonHacksNano / CSI-Camera / simple_camera.py

proin 2020.08.31 14:51 조회 수 : 2

https://github.com/JetsonHacksNano/CSI-Camera/blob/master/simple_camera.py


 

66 lines (58 sloc)  2.02 KB
  # MIT License
  # Copyright (c) 2019 JetsonHacks
  # See license
  # Using a CSI camera (such as the Raspberry Pi Version 2) connected to a
  # NVIDIA Jetson Nano Developer Kit using OpenCV
  # Drivers for the camera and OpenCV are included in the base image
   
  import cv2
   
  # gstreamer_pipeline returns a GStreamer pipeline for capturing from the CSI camera
  # Defaults to 1280x720 @ 60fps
  # Flip the image by setting the flip_method (most common values: 0 and 2)
  # display_width and display_height determine the size of the window on the screen
   
   
  def gstreamer_pipeline(
  capture_width=1280,
  capture_height=720,
  display_width=1280,
  display_height=720,
  framerate=60,
  flip_method=0,
  ):
  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 show_camera():
  # To flip the image, modify the flip_method parameter (0 and 2 are the most common)
  print(gstreamer_pipeline(flip_method=0))
  cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=0), cv2.CAP_GSTREAMER)
  if cap.isOpened():
  window_handle = cv2.namedWindow("CSI Camera", cv2.WINDOW_AUTOSIZE)
  # Window
  while cv2.getWindowProperty("CSI Camera", 0) >= 0:
  ret_val, img = cap.read()
  cv2.imshow("CSI Camera", img)
  # This also acts as
  keyCode = cv2.waitKey(30) & 0xFF
  # Stop the program on the ESC key
  if keyCode == 27:
  break
  cap.release()
  cv2.destroyAllWindows()
  else:
  print("Unable to open camera")
   
   
  if __name__ == "__main__":
  show_camera()

 


 

 

 

번호 제목 글쓴이 날짜 조회 수
20 Jetson에서 카메라 사용 할 때 Failed to create CaptureSession 에러 발생 시 proin 2022.02.08 1
19 Jetson-nano VNC 설정 proin 2020.10.20 4
18 Jetson Nano VNC 설정하기 proin 2020.10.20 3
17 jkjung-avt/openalpr_camera.py proin 2020.10.16 3
16 License Plate Recognition with a Jetson Nano proin 2020.10.16 2
15 Jetson Nano에서 OpenCV 설치 후 virtualenv로 실행할 때 proin 2020.09.22 1
» JetsonHacksNano / CSI-Camera / simple_camera.py proin 2020.08.31 2
13 [OpenCV] Jetson nano에 OpenCV 3.4 설치 proin 2020.08.28 3
12 How to install OpenCV 4.2.0 with CUDA 10.0 in Ubuntu distro 18.04 proin 2020.08.27 3
11 첫 번째 신경망 훈련하기: 기초적인 분류 문제 proin 2020.08.27 1
10 Installing TensorFlow For Jetson Platform proin 2020.08.27 3
9 Quick Start Guide > Preparing a Jetson Developer Kit for Use proin 2020.08.24 1
8 Real-Time Object Detection in 10 Lines of Python on Jetson Nano proin 2020.08.21 2
7 OpenCV 4 + CUDA on Jetson Nano proin 2020.08.21 3
6 mjpg-streamer를 사용한 웹 스트리밍을 OpenCV에서 가져오기 proin 2020.08.20 1
5 jetson-stats 3.0.1 proin 2020.08.20 1
4 Jetson Nano GPIO 사용 해보기 proin 2020.08.20 2
3 [OPENCV] 1. Jetson Nano 보드 ubuntu 18.04에서 OpenCV 설치 및 CUDA 빌드 proin 2020.08.20 5
2 [AI] 젯슨 나노(Jetson Nano) darknet YOLO v3 설치 및 샘플 돌려보기 proin 2020.08.19 3
1 Jetson Nano(젯슨나노) - Ubuntu 기본설치와 5V 4a 전원 어댑터 설치하기 proin 2020.08.19 2
위로