My configuration is: Orange Pie zero2 1G
Kernel version number: Linux 4.9.170-sun50iw9
opencv version: opencv-4.6.0
Camera: 60 yuan USB driver-free camera
This tutorial is not perfect, has no logic, and has many pitfalls. I hope you understand.
You can also use an external screen. You can also log in via ssh to display the image, but it may get stuck.
For the method of installing opencv, please refer to the following blogger's article. It is easy to use after personal testing. Just pay attention to the installation details.
// Pay attention to the CMAKE line -D to delete some spaces. It seems like this. It is not guaranteed to work.
//Furthermore, if you use orange pie make, make -j1 or -j2 will do. If you use more, it will freeze. -j1 will take about three hours. .
//If you know other compilation methods, please tell me
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -D -DOPENCV_ENABLE_NONFREE=True ..
First of all, make sure you have no problem running the routines that come with opencv. If you log in using ssh, you should be able to log in without a screen. This is how it works.
Let's start talking,
First, we
create a folder face in /home/orangepi/opencv-4.6.0/samples/cpp. My path is like this. It can also be called other folders.
Enter face, create a CMakeLists.txt file and copy the routine in the upper folder cpp. Mine is facedetect.cpp and you just need these two things. Write the following content in CMakeCache.txt
In the fifth line of project, write the name of the created folder in brackets.
Lines 23 and 26 also need to be modified. Just take a look at them.
Change line 23 to (folder name xxx.cpp)
Change the first part in the brackets on the twenty-sixth line to the folder name.
1 # cmake needs this line
2 cmake_minimum_required(VERSION 3.1)
3
4 # Define project name
5 project(face)
6
7 # Find OpenCV, you may need to set OpenCV_DIR variable
8 # to the absolute path to the directory containing OpenCVConfig.cmake file
9 # via the command line or GUI
10 find_package(OpenCV REQUIRED)
11
12 # If the package has been found, several variables will
13 # be set, you can find the full list with descriptions
14 # in the OpenCVConfig.cmake file.
15 # Print some message showing some of them
16 message(STATUS "OpenCV library status:")
17 message(STATUS " config: ${OpenCV_DIR}")
18 message(STATUS " version: ${OpenCV_VERSION}")
19 message(STATUS " libraries: ${OpenCV_LIBS}")
20 message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
21
22 # Declare the executable target built from your sources
23 add_executable(face facedetect.cpp)
24
25 # Link your application with OpenCV libraries
26 target_link_libraries(face PRIVATE ${OpenCV_LIBS})
Compare the CMakeLists.txt in the routine to roughly know what it means.
project(opencv_example_project) The last _project seems to be added or not.
1 # cmake needs this line
2 cmake_minimum_required(VERSION 3.1)
3
4 # Define project name
5 project(opencv_example_project)
6
7 # Find OpenCV, you may need to set OpenCV_DIR variable
8 # to the absolute path to the directory containing OpenCVConfig.cmake file
9 # via the command line or GUI
10 find_package(OpenCV REQUIRED)
11
12 # If the package has been found, several variables will
13 # be set, you can find the full list with descriptions
14 # in the OpenCVConfig.cmake file.
15 # Print some message showing some of them
16 message(STATUS "OpenCV library status:")
17 message(STATUS " config: ${OpenCV_DIR}")
18 message(STATUS " version: ${OpenCV_VERSION}")
19 message(STATUS " libraries: ${OpenCV_LIBS}")
20 message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
21
22 # Declare the executable target built from your sources
23 add_executable(opencv_example example.cpp)
24
25 # Link your application with OpenCV libraries
26 target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
Then cmake. Click
cmake .
Then make
make
Then I saw a bunch of things being generated
OK, the executable file is generated, let’s log in and run it through ssh./face
./face
An error is reported, the xml file cannot be found, we open the facedetect.cpp file in our project
Modify the following position, compare the two pictures, and replace it with an absolute path. You can use the pwd command to view the current path.
Run cmke again. Run make again.
camke .
make
ok, let’s run ./face again
Yeah~, that’s it. When recognizing faces on the computer screen, the detection time is about 350ms. If there is no face, it can run to about 100ms.
The ssh method is slightly faster to recognize real faces, about 280ms.
The detection speed of running the display directly on the screen will be faster, taking about 210ms.
Other questions
An error is reported. The serial port login cannot be run. Just change it to ssh login or directly connect to the screen.
Adding a path may not be useful. Enter .bashrc in the workspace.
This tutorial is suitable for students who have a certain foundation. If you have any other questions or areas that need correction, please share them with us!