ssh -Y <user>@<ip>
sudo apt-get install raspi-config
sudo raspi-config
raspistill -o mypicture.jpg
raspivid -o myvideo.h264
pip install "picamera[array]"
sudo apt-get update sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev sudo apt-get install libxvidcore-dev libx264-dev sudo apt-get install libgtk-3-dev sudo apt-get install libatlas-base-dev gfortran sudo apt-get install python2.7-dev python3.5-dev
cd ~ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip unzip opencv_contrib.zip
cd ~/opencv-3.1.0/ mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D INSTALL_C_EXAMPLES=OFF \ -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \ -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python \ -D BUILD_EXAMPLES=ON ..
make -j4
make clean make
sudo make install sudo ldconfig
source ~/.bashrc
mkdir PiCamera && cd PiCamera vim test_cam.py
from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 # initialize the camera and reference the raw camera capture camera = PiCamera() rawCapture = PiRGBArray(camera) # allow camera to warmup time.sleep(0.1) # grab an image camera.capture(rawCapture, format="bgr") image = rawCapture.array cv2.imshow("Capture", image) cv2.waitKey(0)
python test_cam.py
vim test_videom.py
# import the necessary packages from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = (640, 480) camera.framerate = 32 rawCapture = PiRGBArray(camera, size=(640, 480)) # allow the camera to warmup time.sleep(0.1) # capture frames from the camera for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): # grab the raw NumPy array representing the image, then initialize the timestamp # and occupied/unoccupied text image = frame.array # show the frame cv2.imshow("Frame", image) key = cv2.waitKey(1) & 0xFF # clear the stream in preparation for the next frame rawCapture.truncate(0) # if the `q` key was pressed, break from the loop if key == ord("q"): break
from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 import numpy as np # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = (640, 480) camera.framerate = 32 rawCapture = PiRGBArray(camera, size=(640, 480)) # allow the camera to warmup time.sleep(0.1) # capture frames from the camera for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): # grab the raw NumPy array representing the image, then initialize the timestamp # and occupied/unoccupied text image = frame.array hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) lower_red = np.array([30,150,50]) upper_red = np.array([255,255,180]) mask = cv2.inRange(hsv, lower_red, upper_red) res = cv2.bitwise_and(image,image, mask= mask) edges = cv2.Canny(res,100,200) # show the frame cv2.imshow("Frame", image) cv2.imshow("Edges", edges) key = cv2.waitKey(1) & 0xFF # clear the stream in preparation for the next frame rawCapture.truncate(0) # if the `q` key was pressed, break from the loop if key == ord("q"): break
sudo rpi-update
sudo modprobe bcm2835-v4l2
ll /dev/video0
crw-rw----+ 1 root video 81, 0 Mar 17 15:47 /dev/video0
sudo apt-get install ros-kinetic-usb-cam source /opt/ros/kinetic/setup.bash
roscore roslaunch usb_cam usb_cam-test.launch rosrun rqt_image_view rqt_image_view
Source: https://habr.com/ru/post/417251/
All Articles