Skip to content

Commit 6929d47

Browse files
authored
C++ Demo - Image Classification (PPResNet) (#241)
* Functional version of C++ demo. * Improve printout. * Remove printouts and add README examples * Add goldfish example * Add empty space at EOF * Add empty line at EOF for Python * Use the shared labels.txt file instead of having the entire list as a variable in the demo.py * Address PR comments. Revert example and labels * Use namespaces for brevity * Follow OpenCV formatting * Remove LoadLabel() and use a vector of strings instead of having redundant work.
1 parent ef3b465 commit 6929d47

File tree

4 files changed

+1183
-3
lines changed

4 files changed

+1183
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
set(project_name "opencv_zoo_image_classification_ppresnet")
3+
4+
PROJECT (${project_name})
5+
6+
set(OPENCV_VERSION "4.9.0")
7+
set(OPENCV_INSTALLATION_PATH "" CACHE PATH "Where to look for OpenCV installation")
8+
find_package(OpenCV ${OPENCV_VERSION} REQUIRED HINTS ${OPENCV_INSTALLATION_PATH})
9+
# Find OpenCV, you may need to set OpenCV_DIR variable
10+
# to the absolute path to the directory containing OpenCVConfig.cmake file
11+
# via the command line or GUI
12+
13+
file(GLOB SourceFile
14+
"demo.cpp")
15+
# If the package has been found, several variables will
16+
# be set, you can find the full list with descriptions
17+
# in the OpenCVConfig.cmake file.
18+
# Print some message showing some of them
19+
message(STATUS "OpenCV library status:")
20+
message(STATUS " config: ${OpenCV_DIR}")
21+
message(STATUS " version: ${OpenCV_VERSION}")
22+
message(STATUS " libraries: ${OpenCV_LIBS}")
23+
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
24+
25+
# Declare the executable target built from your sources
26+
add_executable(${project_name} ${SourceFile})
27+
28+
# Set C++ compilation standard to C++11
29+
set(CMAKE_CXX_STANDARD 11)
30+
31+
# Link your application with OpenCV libraries
32+
target_link_libraries(${project_name} PRIVATE ${OpenCV_LIBS})

models/image_classification_ppresnet/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,34 @@ Results of accuracy evaluation with [tools/eval](../../tools/eval).
1515

1616
## Demo
1717

18-
Run the following command to try the demo:
18+
Run the following commands to try the demo:
19+
20+
### Python
1921

2022
```shell
2123
python demo.py --input /path/to/image
2224

2325
# get help regarding various parameters
2426
python demo.py --help
2527
```
28+
### C++
29+
30+
Install latest OpenCV and CMake >= 3.24.0 to get started with:
31+
32+
```shell
33+
# A typical and default installation path of OpenCV is /usr/local
34+
cmake -B build -D OPENCV_INSTALLATION_PATH=/path/to/opencv/installation .
35+
cmake --build build
36+
37+
# detect on an image
38+
./build/opencv_zoo_image_classification_ppresnet -i=/path/to/image
39+
40+
# detect on an image and display top N classes
41+
./build/opencv_zoo_image_classification_ppresnet -i=/path/to/image -k=N
42+
43+
# get help messages
44+
./build/opencv_zoo_image_classification_ppresnet -h
45+
```
2646

2747
## License
2848

0 commit comments

Comments
 (0)