Adjust formatting
This commit is contained in:
parent
0f0e3c414a
commit
c0b9022bfc
@ -1,25 +1,20 @@
|
|||||||
# 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
|
import cv2
|
||||||
import numpy as py
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def focusing(val):
|
def focusing(val):
|
||||||
value = (val << 4) & 0x3ff0
|
value = (val << 4) & 0x3ff0
|
||||||
data1 = (value >> 8) & 0x3f
|
data1 = (value >> 8) & 0x3f
|
||||||
data2 = value & 0xf0
|
data2 = value & 0xf0
|
||||||
os.system("i2cset -y 6 0x0c %d %d" % (data1, data2))
|
os.system("i2cset -y 6 0x0c %d %d" % (data1, data2))
|
||||||
|
|
||||||
|
|
||||||
def sobel(img):
|
def sobel(img):
|
||||||
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
||||||
img_sobel = cv2.Sobel(img_gray, cv2.CV_16U, 1, 1)
|
img_sobel = cv2.Sobel(img_gray, cv2.CV_16U, 1, 1)
|
||||||
return cv2.mean(img_sobel)[0]
|
return cv2.mean(img_sobel)[0]
|
||||||
|
|
||||||
|
|
||||||
def laplacian(img):
|
def laplacian(img):
|
||||||
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
|
||||||
img_sobel = cv2.Laplacian(img_gray, cv2.CV_16U)
|
img_sobel = cv2.Laplacian(img_gray, cv2.CV_16U)
|
||||||
@ -31,15 +26,32 @@ def laplacian(img):
|
|||||||
# Flip the image by setting the flip_method (most common values: 0 and 2)
|
# 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
|
# display_width and display_height determine the size of the window on the screen
|
||||||
|
|
||||||
def gstreamer_pipeline (capture_width=1920, capture_height=1080, display_width=1280, display_height=720, framerate=29.99999, flip_method=2) :
|
|
||||||
return ('nvarguscamerasrc ! '
|
def gstreamer_pipeline(capture_width=3264,
|
||||||
|
capture_height=2464,
|
||||||
|
framerate=21,
|
||||||
|
quality=95):
|
||||||
|
return ('nvarguscamerasrc num-buffers=1 ! '
|
||||||
'video/x-raw(memory:NVMM), '
|
'video/x-raw(memory:NVMM), '
|
||||||
'width=(int)%d, height=(int)%d, '
|
'width=(int)%d, height=(int)%d, '
|
||||||
'format=(string)NV12, framerate=(fraction)%d/1 ! '
|
'framerate=(fraction)%d/1 ! '
|
||||||
'nvvidconv flip-method=%d ! '
|
'nvjpegenc quality=%d ! '
|
||||||
'video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! '
|
'appsink' % (capture_width, capture_height, framerate, quality))
|
||||||
'videoconvert ! '
|
|
||||||
'video/x-raw, format=(string)BGR ! appsink' % (capture_width,capture_height,framerate,flip_method,display_width,display_height))
|
|
||||||
|
# def gstreamer_pipeline(capture_width=3264,
|
||||||
|
# capture_height=2464,
|
||||||
|
# framerate=21):
|
||||||
|
# return ('nvarguscamerasrc ! '
|
||||||
|
# 'video/x-raw(memory:NVMM), '
|
||||||
|
# 'width=(int)%d,height=(int)%d, '
|
||||||
|
# 'framerate=(fraction)%d/1 ! '
|
||||||
|
# 'nvvidconv flip-method=2 ! '
|
||||||
|
# 'video/x-raw,format=(string)BGRx ! '
|
||||||
|
# 'videoconvert ! '
|
||||||
|
# 'video/x-raw,format=(string)BGR ! '
|
||||||
|
# 'appsink' % (capture_width, capture_height, framerate))
|
||||||
|
|
||||||
|
|
||||||
def show_camera():
|
def show_camera():
|
||||||
max_index = 10
|
max_index = 10
|
||||||
@ -50,7 +62,8 @@ def show_camera():
|
|||||||
focus_finished = False
|
focus_finished = False
|
||||||
# To flip the image, modify the flip_method parameter (0 and 2 are the most common)
|
# To flip the image, modify the flip_method parameter (0 and 2 are the most common)
|
||||||
print(gstreamer_pipeline(flip_method=2))
|
print(gstreamer_pipeline(flip_method=2))
|
||||||
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=2), cv2.CAP_GSTREAMER)
|
cap = cv2.VideoCapture(gstreamer_pipeline(flip_method=2),
|
||||||
|
cv2.CAP_GSTREAMER)
|
||||||
if cap.isOpened():
|
if cap.isOpened():
|
||||||
window_handle = cv2.namedWindow('CSI Camera', cv2.WINDOW_AUTOSIZE)
|
window_handle = cv2.namedWindow('CSI Camera', cv2.WINDOW_AUTOSIZE)
|
||||||
# Window
|
# Window
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user