Jetson Nano 2GB python code

Shell Cmd

#add swapfile mem
1. free -m                 check mem
2. sudo chmod 600 /var/swapfile
3. sudo mkswap /var/swapfile
4. sudo swapon /var/swapfile
5. sudo bash -c 'echo "/var/swapfile swap swap defaults 0 0" >> /etc/fstab'

#CUDA make 
1. cd cd usr/local/cuda/samples/oceanFFT
2. sudo make
3. ls -ls     
4. sudo ./oceanFFT         execute oceanFFT
5. sudo ./nbody -cpu

#VisionWorks Lib
1. cd /usr/share/visionworks/sources/
2. sudo ./install-samples.sh ~/
3. cd ~/VisionWorks-1.6-Samples&& ls -l
   sudo make -j4 dbg=1
4. cd ./bin/aarch64/linux/debug

#camera device check 
1. sudo apt install v4l-utils     Use 'sudo apt autoremove' to remove them.
2. v4l2-ctl --list-devices
3. v4l2-ctl --device=/dev/video0 --list-formats-ext
   ioctl: VIDIOC_ENUM_FMT
	Index       : 0
	Type        : Video Capture
	Pixel Format: 'RG10'
	Name        : 10-bit Bayer RGRG/GBGB
		Size: Discrete 3264x2464
			Interval: Discrete 0.048s (21.000 fps)
		Size: Discrete 3264x1848
			Interval: Discrete 0.036s (28.000 fps)
		Size: Discrete 1920x1080
			Interval: Discrete 0.033s (30.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)
		Size: Discrete 1280x720
			Interval: Discrete 0.017s (60.000 fps)

Python Demo

CameraCapture

import cv2
import numpy as np
# open CSI camera
camera = cv2.VideoCapture("nvarguscamerasrc \
!video/x-raw(memory:NVMM),width=640,height=480,format=NV12,framerate=30/1 \
!nvvidconv flip-method=0 ! videoconvert !video/x-raw,format=BGR!appsink")

fourcc = cv2.VideoWriter_fourcc(*'mpeg')
#fourcc = int(camera.get(cv2.CAP_PROP_FOURCC))
fps = 30.0 #camera.get(cv2.CAP_PROP_FPS)

width = int(camera.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))

videoOut = cv2.VideoWriter('recorder.mp4',fourcc,fps,(width,height))

isRead,frame = camera.read()
while isRead:
    videoOut.write(frame)
    cv2.imshow('video',frame)
    if cv2.waitKey(30) == 27:
        break

    isRead,frame = camera.read()
# release all resources  
camera.release()
videoOut.release()
cv2.destroyAllWindows()

CameraResize

import cv2
import numpy as np
# open CSI camera
camera = cv2.VideoCapture("nvarguscamerasrc \
!video/x-raw(memory:NVMM),width=640,height=480,format=NV12,framerate=30/1 \
!nvvidconv flip-method=0 ! videoconvert !video/x-raw,format=BGR!appsink")

isRead,frame = camera.read()

while isRead:
    enlarge2 = cv2.resize(frame,(0,0),fx=2.0,fy=2.0,interpolation=cv2.INTER_NEAREST)
    downsize2 = cv2.resize(frame,(0,0),fx=0.5,fy=0.5,interpolation=cv2.INTER_NEAREST)  
    cv2.imshow('rawIMG',frame)
    cv2.imshow('enlarge2IMG',enlarge2)
    cv2.imshow('downsize2',downsize2)

    if cv2.waitKey(30) == 27:
        break

    isRead,frame = camera.read()

# release all resources  
camera.release()
cv2.destroyAllWindows()

CameraColorDetect

import cv2
import numpy as np
# open CSI camera
camera = cv2.VideoCapture("nvarguscamerasrc \
!video/x-raw(memory:NVMM),width=640,height=480,format=NV12,framerate=30/1 \
!nvvidconv flip-method=0 ! videoconvert !video/x-raw,format=BGR!appsink")

greenLowerBound = np.array([40,100,100])
greenUpperBound = np.array([80,255,255])

while camera.isOpened():
    isRead,frame = camera.read()

    # trans from BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
    # calculate mask, 
    mask = cv2.inRange(hsv,greenLowerBound,greenUpperBound)
    detect = cv2.bitwise_and(frame, frame, mask=mask)

    cv2.imshow('RawIMG',frame)
    cv2.imshow('mask',mask)
    cv2.imshow('detect',detect)

    # 'ESC' end
    if cv2.waitKey(30) == 27:
        break

# release all resources  
camera.release()
cv2.destroyAllWindows()

CameraEdgeDetect

import cv2
import numpy as np
# open CSI camera
camera = cv2.VideoCapture("nvarguscamerasrc \
!video/x-raw(memory:NVMM),width=640,height=480,format=NV12,framerate=30/1 \
!nvvidconv flip-method=0 ! videoconvert !video/x-raw,format=BGR!appsink")

while camera.isOpened():
    isRead,frame = camera.read()

    # trans from BGR to HSV
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # Gauss process to gray picture
    blur = cv2.GaussianBlur(hsv,(7,7),1.5)
    # canny edge detect
    edges = cv2.Canny(blur,0,40)

    dispFrame = cv2.resize(frame,(640,360))
    dispHsv = cv2.resize(hsv,(640,360))
    dispBlur = cv2.resize(blur,(640,360))
    dispEdge = cv2.resize(edges,(640,360))

    # (frame + edge) and (hsv + blur) two row, axis = 1
    dispLine1 = np.concatenate((dispFrame, cv2.cvtColor(dispEdge, cv2.COLOR_GRAY2BGR)), axis = 1)
    dispLine2 = np.concatenate((cv2.cvtColor(dispHsv, cv2.COLOR_GRAY2BGR),
                               cv2.cvtColor(dispBlur, cv2.COLOR_GRAY2BGR)),axis = 1)
    # line1 and line2 two column, axis = 0
    dispAll = np.concatenate((dispLine1, dispLine2), axis = 0)
    cv2.imshow("Jetson Nano 2G edge detect Demo", dispAll)
    # 'ESC' end
    if cv2.waitKey(10) == 27:
        break

# release all resources  
camera.release()
cv2.destroyAllWindows()

CameraFace&&eyeDetect

import cv2
import numpy as np
# open CSI camera
camera = cv2.VideoCapture("nvarguscamerasrc \
!video/x-raw(memory:NVMM),width=640,height=480,format=NV12,framerate=30/1 \
!nvvidconv flip-method=0 ! videoconvert !video/x-raw,format=BGR!appsink")

# call OpenCV face_cascade and eye_cascade function
faceCascade = cv2.CascadeClassifier(
"/usr/local/share/opencv4/haarcascades/haarcascade_frontalface_default.xml"
)
eyeCascade = cv2.CascadeClassifier(
"/usr/local/share/opencv4/haarcascades/haarcascade_eye.xml"
)

while camera.isOpened():
    isRead,frame = camera.read()
    cv2.imshow("Jetson Nano 2G face&eye Demo", frame)
    # 
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # 
    faces = faceCascade.detectMultiScale(gray, 1.3, 5)
    for(x,y,w,h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = img[y:y+h, x:x+w]
        eyes = eyeCascade.detectMultiScale(roi_gray)
        for(ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex,ey),(ex+ew,ey+eh),(0,255,0),2)

    cv2.imshow("Jetson Nano 2G face&eye Demo", frame)
    
    # 'ESC' end
    if cv2.waitKey(10) == 27:
        break

# release all resources  
camera.release()
cv2.destroyAllWindows()

#Jetson Nano
jetson nano multiUSB cameras

more-than-two-usb-cameras-problem-on-deepstream

修改bandwith

#!/usr/bin/python3
import time
import serial

print("UART Demonstration Program")
print("NVIDIA Jetson Nano Developer Kit")


serial_port = serial.Serial(
    port="/dev/ttyTHS1",
    baudrate=115200,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
)
# Wait a second to let the port initialize
time.sleep(1)

try:
    # Send a simple header
    serial_port.write("UART Demonstration Program\r\n".encode())
    serial_port.write("NVIDIA Jetson Nano Developer Kit\r\n".encode())
    while True:
        if serial_port.inWaiting() > 0:
            data = serial_port.read()
            print(data)
            serial_port.write(data)
            # if we get a carriage return, add a line feed too
            # \r is a carriage return; \n is a line feed
            # This is to help the tty program on the other end 
            # Windows is \r\n for carriage return, line feed
            # Macintosh and Linux use \n
            if data == "\r".encode():
                # For Windows boxen on the other end
                serial_port.write("\n".encode())


except KeyboardInterrupt:
    print("Exiting Program")

except Exception as exception_error:
    print("Error occurred. Exiting Program")
    print("Error: " + str(exception_error))

finally:
    serial_port.close()
    pass
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值