参看:https://qengineering.eu/install-opencv-4.5-on-jetson-nano.html
学习github上的库:https://github.com/JetsonHacksNano/CSI-Camera
编译的时候出了问题:
gs@nano:~/02_github/CSI-Camera$ python simple_camera.py
nvarguscamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)NV12, framerate=(fraction)60/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)1280, height=(int)720, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3264 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 3264 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;
GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 4
Output Stream W = 1280 H = 720
seconds to Run = 0
Frame Rate = 120.000005
GST_ARGUS: PowerService: requested_clock_Hz=12096000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
Gtk-Message: 18:11:44.084: Failed to load module "canberra-gtk-module"
Traceback (most recent call last):
File "simple_camera.py", line 66, in <module>
show_camera()
File "simple_camera.py", line 51, in show_camera
while cv2.getWindowProperty("CSI Camera", 0) >= 0:
cv2.error: OpenCV(4.1.0) /home/gs/02_github/nano_build_opencv/opencv/modules/highgui/src/window_gtk.cpp:755: error: (-27:Null pointer) NULL window in function 'cvGetModeWindow_GTK'
GST_ARGUS: Cleaning up
(python:11318): GStreamer-CRITICAL **: 18:14:16.624: gst_mini_object_set_qdata: assertion 'object != NULL' failed
CONSUMER: Done Success
GST_ARGUS: Done Success
GST_ARGUS:
PowerServiceHwVic::cleanupResources
gs@nano:~/02_github/CSI-Camera$
查看源码:simple_camera.py,源码中的目录是“/usr/share/Opencv/..”,而我本地不是这个目录,因此修改如下:
face_cascade = cv2.CascadeClassifier(
"/usr/share/opencv4/haarcascades/haarcascade_frontalface_default.xml"
)
eye_cascade = cv2.CascadeClassifier(
"/usr/share/opencv4/haarcascades/haarcascade_eye.xml"
)
cap = cv2.VideoCapture(gstreamer_pipeline(), cv2.CAP_GSTREAMER)
再次运行命令:python face_detect.py 则,成功!
but...,有出现错误了:
Gtk-Message: 18:28:10.809: Failed to load module "canberra-gtk-module"
运行下面的命令:
sudo apt install libcanberra-gtk-module
sudo apt-get install libcanberra-gtk-module
在运行下面的这个命令时,又出错了:
gs@nano:~/02_github/CSI-Camera$ g++ -std=c++11 -Wall -I/usr/lib/opencv simple_camera.cpp -L/usr/lib -lopencv_core -lopencv_highgui -lopencv_videoio -o simple_camera
simple_camera.cpp:10:10: fatal error: opencv2/opencv.hpp: No such file or directory
#include <opencv2/opencv.hpp>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
使用查找命令:
gs@nano:/usr$ find -name opencv.hpp
./include/opencv4/opencv2/opencv.hpp
./local/include/opencv4/opencv2/opencv.hpp
gs@nano:/usr$
得知,我们的库文件目录与命令行中的不一样,于是修改命令中的库文件路经“-I/usr/include/opencv4”,如下:
gs@nano:~/02_github/CSI-Camera$ g++ -std=c++11 -Wall -I/usr/include/opencv4 simple_camera.cpp -L/usr/lib -lopencv_core -lopencv_highgui -lopencv_videoio -o simple_camera
gs@nano:~/02_github/CSI-Camera$
(这一次没有出现问题了......)