├── data ├── images │ ├── bus.jpg │ ├── car.jpg │ ├── cat.jpg │ ├── dog.jpg │ ├── bicycle.jpg │ ├── car_bus.jpg │ ├── car_bicycle.jpg │ └── dog_bicycle.jpg ├── results │ ├── googlenet_dog.png │ └── mobilenetssd_car_bicycle.png └── labels │ ├── voc20.txt │ ├── voc21.txt │ └── imagenet1000.txt ├── movidius_ncs_launch ├── config │ ├── default.yaml │ ├── tinyyolo_v1.yaml │ ├── mobilenetssd.yaml │ ├── inception_v1.yaml │ ├── inception_v2.yaml │ ├── inception_v3.yaml │ ├── inception_v4.yaml │ ├── mobilenet.yaml │ ├── alexnet.yaml │ ├── googlenet.yaml │ └── squeezenet.yaml ├── CMakeLists.txt ├── launch │ ├── ncs_image_launch.py │ └── ncs_stream_launch.py └── package.xml ├── movidius_ncs_lib ├── include │ └── movidius_ncs_lib │ │ ├── mvnc_cpp.hpp │ │ ├── exception_util.hpp │ │ ├── param.hpp │ │ ├── log.hpp │ │ ├── graph.hpp │ │ ├── device.hpp │ │ ├── tensor.hpp │ │ ├── ncs.hpp │ │ ├── result.hpp │ │ └── exception.hpp ├── src │ ├── exception.cpp │ ├── graph.cpp │ ├── exception_util.cpp │ ├── tensor.cpp │ ├── device.cpp │ ├── param.cpp │ ├── ncs.cpp │ └── result.cpp ├── package.xml ├── tests │ └── unittest_environment.cpp └── CMakeLists.txt ├── movidius_ncs_example ├── package.xml ├── src │ ├── image_classification.cpp │ ├── stream_classification.cpp │ ├── image_detection.cpp │ └── stream_detection.cpp └── CMakeLists.txt ├── movidius_ncs_stream ├── include │ └── movidius_ncs_stream │ │ └── ncs_composition.hpp ├── package.xml ├── tests │ └── unittest_stream.cpp ├── CMakeLists.txt └── src │ └── ncs_composition.cpp ├── movidius_ncs_image ├── package.xml ├── include │ └── movidius_ncs_image │ │ └── ncs_server.hpp ├── CMakeLists.txt ├── tests │ └── unittest_image.cpp └── src │ └── ncs_server.cpp ├── doc ├── image_detection.md ├── video_detection.md ├── image_classification.md └── video_classification.md ├── README.md └── LICENSE /data/images/bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/bus.jpg -------------------------------------------------------------------------------- /data/images/car.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/car.jpg -------------------------------------------------------------------------------- /data/images/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/cat.jpg -------------------------------------------------------------------------------- /data/images/dog.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/dog.jpg -------------------------------------------------------------------------------- /data/images/bicycle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/bicycle.jpg -------------------------------------------------------------------------------- /data/images/car_bus.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/car_bus.jpg -------------------------------------------------------------------------------- /movidius_ncs_launch/config/default.yaml: -------------------------------------------------------------------------------- 1 | param_file: mobilenetssd.yaml 2 | input_topic: /camera/color/image_raw 3 | -------------------------------------------------------------------------------- /data/images/car_bicycle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/car_bicycle.jpg -------------------------------------------------------------------------------- /data/images/dog_bicycle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/images/dog_bicycle.jpg -------------------------------------------------------------------------------- /data/results/googlenet_dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/results/googlenet_dog.png -------------------------------------------------------------------------------- /data/results/mobilenetssd_car_bicycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/ros2_intel_movidius_ncs/HEAD/data/results/mobilenetssd_car_bicycle.png -------------------------------------------------------------------------------- /data/labels/voc20.txt: -------------------------------------------------------------------------------- 1 | classes 2 | aeroplane 3 | bicycle 4 | bird 5 | boat 6 | bottle 7 | bus 8 | car 9 | cat 10 | chair 11 | cow 12 | diningtable 13 | dog 14 | horse 15 | motorbike 16 | person 17 | pottedplant 18 | sheep 19 | sofa 20 | train 21 | tvmonitor -------------------------------------------------------------------------------- /data/labels/voc21.txt: -------------------------------------------------------------------------------- 1 | classes 2 | background 3 | aeroplane 4 | bicycle 5 | bird 6 | boat 7 | bottle 8 | bus 9 | car 10 | cat 11 | chair 12 | cow 13 | diningtable 14 | dog 15 | horse 16 | motorbike 17 | person 18 | pottedplant 19 | sheep 20 | sofa 21 | train 22 | tvmonitor 23 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/tinyyolo_v1.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 1 4 | cnn_type: "tinyyolo_v1" 5 | graph_file_path: "/opt/movidius/ncappzoo/caffe/TinyYolo/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/voc20.txt" 7 | network_dimension: 448 8 | channel1_mean: 0 9 | channel2_mean: 0 10 | channel3_mean: 0 11 | scale: 0.00392156 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/mobilenetssd.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 1 4 | cnn_type: "mobilenetssd" 5 | graph_file_path: "/opt/movidius/ncappzoo/caffe/SSD_MobileNet/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/voc21.txt" 7 | network_dimension: 300 8 | channel1_mean: 127.5 9 | channel2_mean: 127.5 10 | channel3_mean: 127.5 11 | scale: 0.007843 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/inception_v1.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "inception_v1" 5 | graph_file_path: "/opt/movidius/ncappzoo/tensorflow/inception_v1/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt" 7 | network_dimension: 224 8 | channel1_mean: 128 9 | channel2_mean: 128 10 | channel3_mean: 128 11 | scale: 0.0078125 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/inception_v2.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "inception_v2" 5 | graph_file_path: "/opt/movidius/ncappzoo/tensorflow/inception_v2/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt" 7 | network_dimension: 224 8 | channel1_mean: 128 9 | channel2_mean: 128 10 | channel3_mean: 128 11 | scale: 0.0078125 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/inception_v3.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "inception_v3" 5 | graph_file_path: "/opt/movidius/ncappzoo/tensorflow/inception_v3/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt" 7 | network_dimension: 299 8 | channel1_mean: 128 9 | channel2_mean: 128 10 | channel3_mean: 128 11 | scale: 0.0078125 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/inception_v4.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "inception_v4" 5 | graph_file_path: "/opt/movidius/ncappzoo/tensorflow/inception_v4/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt" 7 | network_dimension: 299 8 | channel1_mean: 128 9 | channel2_mean: 128 10 | channel3_mean: 128 11 | scale: 0.0078125 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/mobilenet.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "mobilenet" 5 | graph_file_path: "/opt/movidius/ncappzoo/tensorflow/mobilenets/model/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt" 7 | network_dimension: 224 8 | channel1_mean: 127.5 9 | channel2_mean: 127.5 10 | channel3_mean: 127.5 11 | scale: 0.007843 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/alexnet.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "alexnet" 5 | graph_file_path: "/opt/movidius/ncappzoo/caffe/AlexNet/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1000.txt" 7 | network_dimension: 227 8 | channel1_mean: 104.0069879317889 9 | channel2_mean: 116.66876761696767 10 | channel3_mean: 122.6789143406786 11 | scale: 1.0 12 | -------------------------------------------------------------------------------- /movidius_ncs_launch/config/googlenet.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "googlenet" 5 | graph_file_path: "/opt/movidius/ncappzoo/caffe/GoogLeNet/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1000.txt" 7 | network_dimension: 224 8 | channel1_mean: 104.0069879317889 9 | channel2_mean: 116.66876761696767 10 | channel3_mean: 122.6789143406786 11 | scale: 1.0 -------------------------------------------------------------------------------- /movidius_ncs_launch/config/squeezenet.yaml: -------------------------------------------------------------------------------- 1 | device_index: 0 2 | log_level: 0 3 | top_n: 3 4 | cnn_type: "squeezenet" 5 | graph_file_path: "/opt/movidius/ncappzoo/caffe/SqueezeNet/graph" 6 | category_file_path: "/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1000.txt" 7 | network_dimension: 227 8 | channel1_mean: 104.0069879317889 9 | channel2_mean: 116.66876761696767 10 | channel3_mean: 122.6789143406786 11 | scale: 1.0 -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/mvnc_cpp.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__MVNC_CPP_HPP_ 16 | #define MOVIDIUS_NCS_LIB__MVNC_CPP_HPP_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif // MOVIDIUS_NCS_LIB__MVNC_CPP_HPP_ 28 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/exception_util.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__EXCEPTION_UTIL_HPP_ 16 | #define MOVIDIUS_NCS_LIB__EXCEPTION_UTIL_HPP_ 17 | 18 | #include 19 | 20 | namespace movidius_ncs_lib 21 | { 22 | class ExceptionUtil 23 | { 24 | public: 25 | static void tryToThrowMvncException(int code); 26 | }; 27 | } // namespace movidius_ncs_lib 28 | #endif // MOVIDIUS_NCS_LIB__EXCEPTION_UTIL_HPP_ 29 | -------------------------------------------------------------------------------- /movidius_ncs_launch/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5) 16 | project(movidius_ncs_launch) 17 | 18 | find_package(ament_cmake REQUIRED) 19 | 20 | if(BUILD_TESTING) 21 | find_package(ament_lint_auto REQUIRED) 22 | ament_lint_auto_find_test_dependencies() 23 | endif() 24 | 25 | install(DIRECTORY launch 26 | DESTINATION share/${PROJECT_NAME}) 27 | 28 | install(DIRECTORY config 29 | DESTINATION share/${PROJECT_NAME}) 30 | 31 | ament_package() 32 | -------------------------------------------------------------------------------- /movidius_ncs_launch/launch/ncs_image_launch.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from launch.legacy.exit_handler import default_exit_handler 16 | from ros2run.api import get_executable_path 17 | 18 | 19 | def launch(launch_descriptor, argv): 20 | package = 'movidius_ncs_image' 21 | launch_descriptor.add_process( 22 | cmd=[get_executable_path(package_name=package, executable_name='movidius_ncs_image')], 23 | name='movidius_ncs_image', 24 | exit_handler=default_exit_handler,) 25 | return launch_descriptor 26 | -------------------------------------------------------------------------------- /movidius_ncs_launch/launch/ncs_stream_launch.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from launch.legacy.exit_handler import default_exit_handler 16 | from ros2run.api import get_executable_path 17 | 18 | 19 | def launch(launch_descriptor, argv): 20 | package = 'movidius_ncs_stream' 21 | plugin = 'movidius_ncs_stream::NCSComposition' 22 | 23 | # run composition by api_composition_cli 24 | launch_descriptor.add_process( 25 | cmd=[get_executable_path( 26 | package_name='composition', 27 | executable_name='api_composition_cli'), package, plugin], 28 | name='movidius_ncs_stream', 29 | exit_handler=default_exit_handler,) 30 | return launch_descriptor 31 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/param.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__PARAM_HPP_ 16 | #define MOVIDIUS_NCS_LIB__PARAM_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | namespace movidius_ncs_lib 22 | { 23 | class Param 24 | { 25 | public: 26 | using Ptr = std::shared_ptr; 27 | using ConstPtr = std::shared_ptr; 28 | 29 | Param(); 30 | 31 | bool loadParamFromYAML(const std::string & file_path); 32 | bool validateParam(); 33 | 34 | int device_index_; 35 | int log_level_; 36 | std::string cnn_type_; 37 | std::string graph_file_path_; 38 | std::string category_file_path_; 39 | int network_dimension_; 40 | float channel1_mean_; 41 | float channel2_mean_; 42 | float channel3_mean_; 43 | float scale_; 44 | int top_n_; 45 | }; 46 | } // namespace movidius_ncs_lib 47 | 48 | #endif // MOVIDIUS_NCS_LIB__PARAM_HPP_ 49 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/log.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__LOG_HPP_ 16 | #define MOVIDIUS_NCS_LIB__LOG_HPP_ 17 | 18 | #include 19 | 20 | namespace movidius_ncs_lib 21 | { 22 | #define ROS_ERROR_STREAM(str) std::cout << "[ERROR] [movidius_ncs_lib]: " << str << std::endl 23 | 24 | #define ROS_WARN_STREAM(str) std::cout << "[WARN] [movidius_ncs_lib]: " << str << std::endl 25 | 26 | #define ROS_INFO_STREAM(str) std::cout << "[INFO] [movidius_ncs_lib]: " << str << std::endl 27 | 28 | #define ROS_ERROR(str) std::cout << "[ERROR] [movidius_ncs_lib]: " << str << std::endl 29 | 30 | #define ROS_WARN(str) std::cout << "[WARN] [movidius_ncs_lib]: " << str << std::endl 31 | 32 | #define ROS_INFO(str) std::cout << "[INFO] [movidius_ncs_lib]: " << str << std::endl 33 | 34 | #define ROS_DEBUG(str) std::cout << "[DEBUG] [movidius_ncs_lib]: " << str << std::endl 35 | } // namespace movidius_ncs_lib 36 | #endif // MOVIDIUS_NCS_LIB__LOG_HPP_ 37 | -------------------------------------------------------------------------------- /movidius_ncs_launch/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | movidius_ncs_launch 21 | 0.3.0 22 | This launch project is for Movidius NCS 23 | Xiaojun Huang 24 | Xiaojun Huang 25 | Chao Li 26 | 27 | Apache 2.0 28 | 29 | 30 | 31 | ament_cmake 32 | 33 | launch 34 | ros2run 35 | 36 | ament_lint_auto 37 | ament_lint_common 38 | 39 | 40 | ament_cmake 41 | 42 | 43 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/exception.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | namespace movidius_ncs_lib 18 | { 19 | const char * MvncHighThermal::what() const noexcept 20 | { 21 | return "lower guard temperature threshold is reached, short throtting is in action"; 22 | } 23 | 24 | const char * MvncAggressiveThermal::what() const noexcept 25 | { 26 | return "upper guard temperature threshold is reached, long throtting is in action"; 27 | } 28 | 29 | const char * NCSGraphFileError::what() const noexcept 30 | { 31 | return "cannot load graph"; 32 | } 33 | 34 | const char * NCSMeanAndStddevError::what() const noexcept 35 | { 36 | return "cannot load mean and stddev"; 37 | } 38 | 39 | const char * NCSInputSizeFileError::what() const noexcept 40 | { 41 | return "cannot open inputsize file"; 42 | } 43 | 44 | const char * NCSInputSizeError::what() const noexcept 45 | { 46 | return "cannot load inputsize"; 47 | } 48 | 49 | const char * NCSLoadCategoriesError::what() const noexcept 50 | { 51 | return "cannot load categories"; 52 | } 53 | } // namespace movidius_ncs_lib 54 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/graph.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__GRAPH_HPP_ 16 | #define MOVIDIUS_NCS_LIB__GRAPH_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "movidius_ncs_lib/mvnc_cpp.hpp" 24 | #include "movidius_ncs_lib/result.hpp" 25 | #include "movidius_ncs_lib/tensor.hpp" 26 | #include "movidius_ncs_lib/device.hpp" 27 | 28 | namespace movidius_ncs_lib 29 | { 30 | class Graph 31 | { 32 | public: 33 | using Ptr = std::shared_ptr; 34 | using ConstPtr = std::shared_ptr; 35 | 36 | Graph(const Device::Ptr & device, const std::string & graph_file, int network_dimension); 37 | ~Graph(); 38 | 39 | void allocate(void * device_handle); 40 | void deallocate(); 41 | float getTimeTaken(); 42 | std::string getDebugInfo(); 43 | void * getHandle(); 44 | 45 | int getNetworkDim() const 46 | { 47 | return network_dimension_; 48 | } 49 | 50 | private: 51 | std::string graph_buf_; 52 | const int network_dimension_; 53 | void * handle_; 54 | }; 55 | } // namespace movidius_ncs_lib 56 | 57 | #endif // MOVIDIUS_NCS_LIB__GRAPH_HPP_ 58 | -------------------------------------------------------------------------------- /movidius_ncs_lib/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | movidius_ncs_lib 21 | 0.3.0 22 | The Movidius NCS library package 23 | Xiaojun Huang 24 | Xiaojun Huang 25 | Chao Li 26 | 27 | Apache 2.0 28 | 29 | 30 | 31 | ament_cmake 32 | 33 | rviz_yaml_cpp_vendor 34 | rclcpp 35 | 36 | rviz_yaml_cpp_vendor 37 | rclcpp 38 | 39 | ament_lint_auto 40 | ament_lint_common 41 | 42 | ament_cmake_gtest 43 | 44 | 45 | ament_cmake 46 | 47 | 48 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/device.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__DEVICE_HPP_ 16 | #define MOVIDIUS_NCS_LIB__DEVICE_HPP_ 17 | 18 | #include 19 | #include 20 | #include "movidius_ncs_lib/mvnc_cpp.hpp" 21 | 22 | namespace movidius_ncs_lib 23 | { 24 | class Device 25 | { 26 | public: 27 | using Ptr = std::shared_ptr; 28 | using ConstPtr = std::shared_ptr; 29 | 30 | enum LogLevel 31 | { 32 | Nothing, 33 | Errors, 34 | Verbose 35 | }; 36 | 37 | Device(int index, LogLevel log_level); 38 | ~Device(); 39 | 40 | void setLogLevel(LogLevel level); 41 | LogLevel getLogLevel(); 42 | void * getHandle(); 43 | std::string getName() const; 44 | void monitorThermal() const; 45 | 46 | private: 47 | enum ThermalThrottlingLevel 48 | { 49 | Normal, 50 | High, 51 | Aggressive 52 | }; 53 | 54 | void open(); 55 | void close(); 56 | 57 | void find(); 58 | ThermalThrottlingLevel getThermalThrottlingLevel() const; 59 | 60 | int index_; 61 | std::string name_; 62 | void * handle_; 63 | }; 64 | } // namespace movidius_ncs_lib 65 | 66 | #endif // MOVIDIUS_NCS_LIB__DEVICE_HPP_ 67 | -------------------------------------------------------------------------------- /movidius_ncs_example/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | movidius_ncs_example 20 | 0.3.0 21 | The example package 22 | Xiaojun Huang 23 | Xiaojun Huang 24 | Chao Li 25 | 26 | 27 | 28 | Apache 2.0 29 | 30 | ament_cmake 31 | 32 | rclcpp 33 | object_msgs 34 | sensor_msgs 35 | message_filters 36 | cv_bridge 37 | 38 | rclcpp 39 | object_msgs 40 | sensor_msgs 41 | 42 | ament_lint_auto 43 | ament_lint_common 44 | 45 | 46 | ament_cmake 47 | 48 | 49 | -------------------------------------------------------------------------------- /movidius_ncs_stream/include/movidius_ncs_stream/ncs_composition.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_STREAM__NCS_COMPOSITION_HPP_ 16 | #define MOVIDIUS_NCS_STREAM__NCS_COMPOSITION_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "movidius_ncs_lib/ncs.hpp" 28 | #include "movidius_ncs_lib/param.hpp" 29 | 30 | namespace movidius_ncs_stream 31 | { 32 | class NCSComposition : public rclcpp::Node 33 | { 34 | public: 35 | __attribute__((visibility("default"))) NCSComposition(); 36 | ~NCSComposition(); 37 | 38 | private: 39 | int encoding2mat_type(const std::string & encoding); 40 | void cbClassify(const sensor_msgs::msg::Image::SharedPtr img); 41 | void cbDetect(const sensor_msgs::msg::Image::SharedPtr img); 42 | void init(); 43 | 44 | std::shared_ptr ncs_handle_; 45 | 46 | rclcpp::Publisher::SharedPtr pub_classified_objects_; 47 | rclcpp::Publisher::SharedPtr pub_detected_objects_; 48 | rclcpp::Subscription::SharedPtr sub_; 49 | 50 | movidius_ncs_lib::Param::Ptr param_; 51 | std::string input_topic_; 52 | }; 53 | } // namespace movidius_ncs_stream 54 | 55 | #endif // MOVIDIUS_NCS_STREAM__NCS_COMPOSITION_HPP_ 56 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/tensor.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__TENSOR_HPP_ 16 | #define MOVIDIUS_NCS_LIB__TENSOR_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "movidius_ncs_lib/mvnc_cpp.hpp" 24 | 25 | namespace movidius_ncs_lib 26 | { 27 | class Tensor 28 | { 29 | public: 30 | using Ptr = std::shared_ptr; 31 | using ConstPtr = std::shared_ptr; 32 | 33 | Tensor(const std::pair & net_dim, const std::vector & mean, const float & scale); 34 | 35 | void loadImageData(const cv::Mat & image); 36 | void clearTensor(); 37 | 38 | inline const uint16_t * raw() const 39 | { 40 | return &tensor_[0]; 41 | } 42 | inline const size_t size() const 43 | { 44 | return 3 * net_height_ * net_width_ * sizeof(uint16_t); 45 | } 46 | inline int getImageWidth() 47 | { 48 | return image_width_; 49 | } 50 | inline int getImageHeight() 51 | { 52 | return image_height_; 53 | } 54 | 55 | #ifndef SUPPORT_F16C 56 | static void fp32tofp16(uint16_t * __restrict out, float in); 57 | static void fp16tofp32(float * __restrict out, uint16_t in); 58 | #endif 59 | 60 | private: 61 | std::vector tensor_; 62 | int net_width_; 63 | int net_height_; 64 | int image_width_; 65 | int image_height_; 66 | std::vector mean_; 67 | float scale_; 68 | }; 69 | } // namespace movidius_ncs_lib 70 | 71 | #endif // MOVIDIUS_NCS_LIB__TENSOR_HPP_ 72 | -------------------------------------------------------------------------------- /movidius_ncs_image/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | movidius_ncs_image 21 | 0.3.0 22 | Movidius NCS node for image 23 | Xiaojun Huang 24 | Xiaojun Huang 25 | Chao Li 26 | 27 | Apache 2.0 28 | 29 | 30 | 31 | ament_cmake 32 | 33 | ament_index_cpp 34 | rclcpp 35 | sensor_msgs 36 | object_msgs 37 | movidius_ncs_lib 38 | rviz_yaml_cpp_vendor 39 | 40 | ament_index_cpp 41 | rclcpp 42 | sensor_msgs 43 | object_msgs 44 | movidius_ncs_lib 45 | rviz_yaml_cpp_vendor 46 | 47 | ament_lint_auto 48 | ament_lint_common 49 | 50 | ament_cmake_gtest 51 | 52 | 53 | ament_cmake 54 | 55 | 56 | -------------------------------------------------------------------------------- /movidius_ncs_image/include/movidius_ncs_image/ncs_server.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_IMAGE__NCS_SERVER_HPP_ 16 | #define MOVIDIUS_NCS_IMAGE__NCS_SERVER_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "movidius_ncs_lib/ncs.hpp" 27 | #include "movidius_ncs_lib/param.hpp" 28 | 29 | namespace movidius_ncs_image 30 | { 31 | class NCSServer : public rclcpp::Node 32 | { 33 | public: 34 | explicit NCSServer(const std::string & service_name); 35 | 36 | private: 37 | void getParameters(); 38 | void init(const std::string & service_name); 39 | 40 | void cbClassifyObject( 41 | const std::shared_ptr request_header, 42 | const std::shared_ptr request, 43 | std::shared_ptr response); 44 | void cbDetectObject( 45 | const std::shared_ptr request_header, 46 | const std::shared_ptr request, 47 | std::shared_ptr response); 48 | 49 | rclcpp::Service::SharedPtr service_classify_; 50 | rclcpp::Service::SharedPtr service_detect_; 51 | 52 | std::shared_ptr ncs_handle_; 53 | 54 | movidius_ncs_lib::Param::Ptr param_; 55 | }; 56 | } // namespace movidius_ncs_image 57 | 58 | #endif // MOVIDIUS_NCS_IMAGE__NCS_SERVER_HPP_ 59 | -------------------------------------------------------------------------------- /movidius_ncs_stream/package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | movidius_ncs_stream 21 | 0.3.0 22 | Movidius NCS node for stream 23 | Xiaojun Huang 24 | Xiaojun Huang 25 | Chao Li 26 | 27 | Apache 2.0 28 | 29 | 30 | 31 | ament_cmake 32 | 33 | ament_index_cpp 34 | class_loader 35 | object_msgs 36 | movidius_ncs_lib 37 | rclcpp 38 | rviz_yaml_cpp_vendor 39 | sensor_msgs 40 | cv_bridge 41 | 42 | ament_index_cpp 43 | class_loader 44 | object_msgs 45 | movidius_ncs_lib 46 | rclcpp 47 | rviz_yaml_cpp_vendor 48 | sensor_msgs 49 | 50 | ament_lint_auto 51 | ament_lint_common 52 | 53 | ament_cmake_gtest 54 | 55 | 56 | ament_cmake 57 | 58 | 59 | -------------------------------------------------------------------------------- /doc/image_detection.md: -------------------------------------------------------------------------------- 1 | ## Detection for Image 2 | This project supports multiple CNN models for detection. Please make sure you have already [set up environment](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#3-environment-setup) and [installed this project](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#4-building-and-installation) correctly. You can refer to the following links for your interested models then. 3 | #### [1 CNN Models](#1-cnn-models-1) 4 | * [MobileNet_SSD](#mobilenet_ssd) 5 | * [TinyYolo_V1](#tinyyolo_v1) 6 | #### [2 Other Arguments](#2-other-arguments-1) 7 | ---------------------------------- 8 | 9 | ### 1 CNN Models 10 | * #### MobileNet_SSD 11 | Compile NCS graph. 12 | ```Shell 13 | cd /opt/movidius/ncappzoo/caffe/SSD_MobileNet 14 | make 15 | ``` 16 | Launch object detection service. 17 | ```Shell 18 | cd ~/ros2_ws 19 | echo "param_file: mobilenetssd.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 20 | ament build 21 | source install/local_setup.bash 22 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 23 | ``` 24 | Run the example application with an absolute path of an image on another console. For example, 25 | ```Shell 26 | ros2 run movidius_ncs_example movidius_ncs_example_image_detection /opt/movidius/ncappzoo/data/images/cat.jpg 27 | ``` 28 | * #### TinyYolo_V1 29 | Compile NCS graph. 30 | ```Shell 31 | cd /opt/movidius/ncappzoo/caffe/TinyYolo 32 | make 33 | ``` 34 | Launch object detection service. 35 | ```Shell 36 | cd ~/ros2_ws 37 | echo "param_file: tinyyolo_v1.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 38 | ament build 39 | source install/local_setup.bash 40 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 41 | ``` 42 | Run the example application with an absolute path of an image on another console. For example, 43 | ```Shell 44 | ros2 run movidius_ncs_example movidius_ncs_example_image_detection /opt/movidius/ncappzoo/data/images/cat.jpg 45 | ``` 46 | ### 2 Other Arguments 47 | |Arguments|Description|Default Value|Valid Values| 48 | |:-|:-|:-|:-| 49 | |device_index|ncs device index|0|0~N-1(N is the maximum number of inserted NCS devices)| 50 | |log_level|ncs log level|0|0:Nothing / 1:Errors / 2:Verbose| 51 | |cnn_type|indicate different cnn models|tinyyolo_v1|tinyyolo_v1 / mobilenetssd| 52 | -------------------------------------------------------------------------------- /movidius_ncs_example/src/image_classification.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | int main(int argc, char ** argv) 20 | { 21 | rclcpp::init(argc, argv); 22 | 23 | auto node = rclcpp::Node::make_shared("movidius_ncs_example"); 24 | 25 | if (argc != 2) { 26 | RCLCPP_INFO(node->get_logger(), 27 | "Usage: ros2 run movidius_ncs_example movidius_ncs_example_image_classification " 28 | ""); 29 | return -1; 30 | } 31 | 32 | auto client = node->create_client("movidius_ncs_image/" 33 | "classify_object"); 34 | auto request = std::make_shared(); 35 | request->image_path = argv[1]; 36 | 37 | while (!client->wait_for_service(std::chrono::seconds(1))) { 38 | if (!rclcpp::ok()) { 39 | RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting."); 40 | return 1; 41 | } 42 | RCLCPP_INFO(node->get_logger(), "service not available, waiting again..."); 43 | } 44 | 45 | auto result = client->async_send_request(request); 46 | 47 | if (rclcpp::spin_until_future_complete(node, result) == 48 | rclcpp::executor::FutureReturnCode::SUCCESS) 49 | { 50 | auto srv = result.get(); 51 | for (unsigned int i = 0; i < srv->objects.objects_vector.size(); i++) { 52 | RCLCPP_INFO(node->get_logger(), "%d: object: %s\nprobability: %lf%%", i, 53 | srv->objects.objects_vector[i].object_name.c_str(), 54 | srv->objects.objects_vector[i].probability * 100); 55 | } 56 | RCLCPP_INFO(node->get_logger(), "inference time: %fms", srv->objects.inference_time_ms); 57 | } 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/ncs.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__NCS_HPP_ 16 | #define MOVIDIUS_NCS_LIB__NCS_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include "movidius_ncs_lib/result.hpp" 22 | #include "movidius_ncs_lib/graph.hpp" 23 | #include "movidius_ncs_lib/device.hpp" 24 | 25 | namespace movidius_ncs_lib 26 | { 27 | class NCS 28 | { 29 | public: 30 | NCS( 31 | int device_index, Device::LogLevel log_level, const std::string & cnn_type, 32 | const std::string & graph_file_path, const std::string & category_file_path, 33 | const int network_dimension, const std::vector & mean, const float & scale, 34 | const int & top_n); 35 | ~NCS(); 36 | 37 | void classify(); 38 | void detect(); 39 | void loadTensor(const cv::Mat & image); 40 | ClassificationResultPtr getClassificationResult(); 41 | DetectionResultPtr getDetectionResult(); 42 | 43 | private: 44 | void initDevice(); 45 | void loadGraph(const std::string & graph_file_path); 46 | void loadCategories(const std::string & category_file_path); 47 | static void splitIntoLines(const std::string & content, std::vector & lines); 48 | static std::string getFileContent(const std::string & filename); 49 | 50 | Device::Ptr device_; 51 | Graph::Ptr graph_; 52 | Tensor::Ptr tensor_; 53 | Result::Ptr result_; 54 | 55 | const int device_index_; 56 | const Device::LogLevel log_level_; 57 | const std::string cnn_type_; 58 | std::vector categories_; 59 | const int network_dimension_; 60 | const std::vector mean_; 61 | const float scale_; 62 | const int top_n_; 63 | void * user_param_; 64 | }; 65 | } // namespace movidius_ncs_lib 66 | #endif // MOVIDIUS_NCS_LIB__NCS_HPP_ 67 | -------------------------------------------------------------------------------- /movidius_ncs_lib/tests/unittest_environment.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | TEST(UnitTestEnvironment, testSDK) { 23 | std::system("python2 /opt/movidius/NCSDK/tests/api-check/ncs-python2-check.py > " 24 | "/tmp/NCS_unittest.txt"); 25 | EXPECT_TRUE(std::ifstream("/tmp/NCS_unittest.txt").is_open()); 26 | std::ifstream fin("/tmp/NCS_unittest.txt"); 27 | std::string ncs_check, tmp; 28 | while (std::getline(fin, tmp)) { 29 | ncs_check = tmp; 30 | } 31 | EXPECT_EQ(ncs_check, "NCS device working."); 32 | std::system("rm -rf /tmp/NCS_unittest.txt > /dev/null 2>&1"); 33 | } 34 | 35 | TEST(UnitTestEnvironment, testAppZoo) { 36 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo").is_open()); 37 | std::vector caffe_dirs = {"AlexNet", "GoogLeNet", "SqueezeNet", 38 | "SSD_MobileNet", "TinyYolo"}; 39 | std::vector tf_dirs = {"inception_v1", "inception_v2", "inception_v3", 40 | "inception_v4", "mobilenets/model"}; 41 | for (std::string caffe : caffe_dirs) { 42 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/caffe/" + caffe + "/graph").is_open()); 43 | } 44 | 45 | for (std::string tf : tf_dirs) { 46 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/tensorflow/" + tf + "/graph").is_open()); 47 | } 48 | } 49 | 50 | TEST(UnitTestEnvironment, testCategories) { 51 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1000.txt").is_open()); 52 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/data/ilsvrc12/imagenet1001.txt").is_open()); 53 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/data/ilsvrc12/voc20.txt").is_open()); 54 | EXPECT_TRUE(std::ifstream("/opt/movidius/ncappzoo/data/ilsvrc12/voc21.txt").is_open()); 55 | } 56 | 57 | int main(int argc, char * argv[]) 58 | { 59 | testing::InitGoogleTest(&argc, argv); 60 | rclcpp::init(argc, argv); 61 | return RUN_ALL_TESTS(); 62 | } 63 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/result.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__RESULT_HPP_ 16 | #define MOVIDIUS_NCS_LIB__RESULT_HPP_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | namespace movidius_ncs_lib 23 | { 24 | struct Item 25 | { 26 | std::string category; 27 | float probability; 28 | }; 29 | 30 | struct BBox 31 | { 32 | int x; 33 | int y; 34 | int width; 35 | int height; 36 | }; 37 | 38 | struct ItemInBBox 39 | { 40 | Item item; 41 | BBox bbox; 42 | }; 43 | 44 | using Items = std::vector; 45 | using ItemsPtr = std::shared_ptr; 46 | using ItemInBBoxArray = std::vector; 47 | using ItemInBBoxArrayPtr = std::shared_ptr; 48 | 49 | struct ClassificationResult 50 | { 51 | Items items; 52 | float time_taken; 53 | }; 54 | 55 | struct DetectionResult 56 | { 57 | ItemInBBoxArray items_in_boxes; 58 | float time_taken; 59 | }; 60 | 61 | using ClassificationResultPtr = std::shared_ptr; 62 | using DetectionResultPtr = std::shared_ptr; 63 | 64 | class Result 65 | { 66 | public: 67 | using Ptr = std::shared_ptr; 68 | using ConstPtr = std::shared_ptr; 69 | 70 | explicit Result(const std::string & cnn_type); 71 | ClassificationResultPtr getClassificationResult(); 72 | DetectionResultPtr getDetectionResult(); 73 | void setClassificationResult(Item item); 74 | void setClassificationResult(float time); 75 | void setDetectionResult(ItemInBBox item); 76 | void setDetectionResult(float time); 77 | void parseYoloResult( 78 | const std::vector & result, const std::vector categories, 79 | int img_width, int img_height); 80 | void parseSSDResult( 81 | const std::vector & result, const std::vector categories, 82 | int img_width, int img_height); 83 | 84 | private: 85 | void NMS(ItemInBBoxArrayPtr objs_in_bboxes); 86 | float IOU(ItemInBBox box1, ItemInBBox box2); 87 | 88 | ClassificationResultPtr classification_result; 89 | DetectionResultPtr detection_result; 90 | }; 91 | } // namespace movidius_ncs_lib 92 | 93 | #endif // MOVIDIUS_NCS_LIB__RESULT_HPP_ 94 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/graph.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "movidius_ncs_lib/exception.hpp" 21 | #include "movidius_ncs_lib/exception_util.hpp" 22 | #include "movidius_ncs_lib/graph.hpp" 23 | #include "movidius_ncs_lib/log.hpp" 24 | #include "movidius_ncs_lib/tensor.hpp" 25 | 26 | namespace movidius_ncs_lib 27 | { 28 | Graph::Graph( 29 | const std::shared_ptr & device, const std::string & graph_buf, 30 | int network_dimension) 31 | : graph_buf_(graph_buf), network_dimension_(network_dimension), handle_(nullptr) 32 | { 33 | allocate(device->getHandle()); 34 | } 35 | 36 | Graph::~Graph() 37 | { 38 | try { 39 | deallocate(); 40 | } catch (MvncException & e) { 41 | ROS_ERROR_STREAM(e.what()); 42 | } 43 | } 44 | 45 | std::string Graph::getDebugInfo() 46 | { 47 | assert(handle_ != nullptr); 48 | char * debug_info; 49 | unsigned int length; 50 | int ret = 51 | mvncGetGraphOption(handle_, MVNC_DEBUG_INFO, reinterpret_cast(&debug_info), &length); 52 | ExceptionUtil::tryToThrowMvncException(ret); 53 | std::string result(debug_info); 54 | return result; 55 | } 56 | 57 | float Graph::getTimeTaken() 58 | { 59 | assert(handle_ != nullptr); 60 | float * time_taken; 61 | unsigned int length; 62 | int ret = 63 | mvncGetGraphOption(handle_, MVNC_TIME_TAKEN, reinterpret_cast(&time_taken), &length); 64 | ExceptionUtil::tryToThrowMvncException(ret); 65 | length /= sizeof(*time_taken); 66 | float sum = 0; 67 | 68 | for (unsigned int i = 0; i < length; ++i) { 69 | sum += time_taken[i]; 70 | } 71 | 72 | return sum; 73 | } 74 | 75 | void * Graph::getHandle() 76 | { 77 | assert(handle_ != nullptr); 78 | return handle_; 79 | } 80 | 81 | void Graph::allocate(void * device_handle) 82 | { 83 | int ret = mvncAllocateGraph(device_handle, &handle_, graph_buf_.c_str(), graph_buf_.size()); 84 | ExceptionUtil::tryToThrowMvncException(ret); 85 | } 86 | 87 | void Graph::deallocate() 88 | { 89 | int ret = mvncDeallocateGraph(handle_); 90 | ExceptionUtil::tryToThrowMvncException(ret); 91 | } 92 | } // namespace movidius_ncs_lib 93 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/exception_util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "movidius_ncs_lib/exception_util.hpp" 16 | #include 17 | #include 18 | #include 19 | #include "movidius_ncs_lib/exception.hpp" 20 | #include "movidius_ncs_lib/mvnc_cpp.hpp" 21 | 22 | namespace movidius_ncs_lib 23 | { 24 | std::map CODE2STR = { 25 | {MVNC_BUSY, "device is busy, retry later"}, 26 | {MVNC_ERROR, "an unexpected error was encontered during the function call"}, 27 | {MVNC_OUT_OF_MEMORY, "the host is out of memory"}, 28 | {MVNC_DEVICE_NOT_FOUND, "there is no device at the given index or name"}, 29 | {MVNC_INVALID_PARAMETERS, "at least one of the given parameters is invalid in the context of " 30 | "the function call"}, 31 | {MVNC_TIMEOUT, "timeout in the communication with the device"}, 32 | {MVNC_MVCMD_NOT_FOUND, "the file named MvNCAPI.mvcmd should be installed in the mvnc " 33 | "direcotry"}, 34 | {MVNC_NO_DATA, "no data to return"}, 35 | {MVNC_GONE, "the graph or device has been closed during the operation"}, 36 | {MVNC_UNSUPPORTED_GRAPH_FILE, "the graph file may have been created with an incompatible prior " 37 | "version of the Toolkit"}, 38 | {MVNC_MYRIAD_ERROR, "an error has been reported by Movidius VPU"} 39 | }; 40 | 41 | void ExceptionUtil::tryToThrowMvncException(int code) 42 | { 43 | assert(MVNC_OK >= code && code >= MVNC_MYRIAD_ERROR); 44 | 45 | try { 46 | const std::string msg = CODE2STR.at(code); 47 | 48 | if (code == MVNC_BUSY) { 49 | throw MvncBusy(msg); 50 | } 51 | 52 | if (code == MVNC_ERROR) { 53 | throw MvncError(msg); 54 | } 55 | 56 | if (code == MVNC_OUT_OF_MEMORY) { 57 | throw MvncOutOfMemory(msg); 58 | } 59 | 60 | if (code == MVNC_DEVICE_NOT_FOUND) { 61 | throw MvncDeviceNotFound(msg); 62 | } 63 | 64 | if (code == MVNC_INVALID_PARAMETERS) { 65 | throw MvncInvalidParameters(msg); 66 | } 67 | 68 | if (code == MVNC_TIMEOUT) { 69 | throw MvncTimeout(msg); 70 | } 71 | 72 | if (code == MVNC_MVCMD_NOT_FOUND) { 73 | throw MvncMvCmdNotFound(msg); 74 | } 75 | 76 | if (code == MVNC_NO_DATA) { 77 | throw MvncNoData(msg); 78 | } 79 | 80 | if (code == MVNC_GONE) { 81 | throw MvncGone(msg); 82 | } 83 | 84 | if (code == MVNC_UNSUPPORTED_GRAPH_FILE) { 85 | throw MvncUnsupportedGraphFile(msg); 86 | } 87 | 88 | if (code == MVNC_MYRIAD_ERROR) { 89 | throw MvncMyriadError(msg); 90 | } 91 | } catch (std::out_of_range & e) { 92 | } 93 | } 94 | } // namespace movidius_ncs_lib 95 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/tensor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #ifdef SUPPORT_F16C 19 | #include 20 | #endif 21 | #include 22 | #include "movidius_ncs_lib/tensor.hpp" 23 | 24 | namespace movidius_ncs_lib 25 | { 26 | Tensor::Tensor( 27 | const std::pair & net_dim, const std::vector & mean, 28 | const float & scale) 29 | : tensor_(0), 30 | net_width_(net_dim.first), 31 | net_height_(net_dim.second), 32 | image_width_(0), 33 | image_height_(0), 34 | mean_(mean), 35 | scale_(scale) 36 | { 37 | } 38 | 39 | void Tensor::loadImageData(const cv::Mat & image) 40 | { 41 | image_width_ = image.cols; 42 | image_height_ = image.rows; 43 | 44 | cv::Mat resized; 45 | cv::resize(image, resized, cv::Size(net_width_, net_height_), 0, 0); 46 | 47 | cv::Mat colored; 48 | cv::cvtColor(resized, colored, cv::COLOR_RGB2BGR); 49 | 50 | cv::Mat converted; 51 | colored.convertTo(converted, CV_32FC3); 52 | 53 | using TensorIt = cv::MatConstIterator_; 54 | 55 | for (TensorIt it = converted.begin(); it != converted.end(); ++it) { 56 | float r32 = ((*it)[0] - mean_[0]) * scale_; 57 | float g32 = ((*it)[1] - mean_[1]) * scale_; 58 | float b32 = ((*it)[2] - mean_[2]) * scale_; 59 | uint16_t r16; 60 | uint16_t g16; 61 | uint16_t b16; 62 | #ifdef SUPPORT_F16C 63 | r16 = _cvtss_sh(r32, 0); 64 | g16 = _cvtss_sh(g32, 0); 65 | b16 = _cvtss_sh(b32, 0); 66 | #else 67 | Tensor::fp32tofp16(&r16, r32); 68 | Tensor::fp32tofp16(&g16, g32); 69 | Tensor::fp32tofp16(&b16, b32); 70 | #endif 71 | tensor_.push_back(r16); 72 | tensor_.push_back(g16); 73 | tensor_.push_back(b16); 74 | } 75 | } 76 | 77 | void Tensor::clearTensor() 78 | { 79 | if (!tensor_.empty()) { 80 | tensor_.clear(); 81 | } 82 | } 83 | 84 | #ifndef SUPPORT_F16C 85 | void Tensor::fp16tofp32(float * __restrict out, uint16_t in) 86 | { 87 | uint32_t t1; 88 | uint32_t t2; 89 | uint32_t t3; 90 | t1 = in & 0x7fff; 91 | t2 = in & 0x8000; 92 | t3 = in & 0x7c00; 93 | t1 <<= 13; 94 | t2 <<= 16; 95 | t1 += 0x38000000; 96 | t1 = (t3 == 0 ? 0 : t1); 97 | t1 |= t2; 98 | *(reinterpret_cast(out)) = t1; 99 | } 100 | 101 | void Tensor::fp32tofp16(uint16_t * __restrict out, float in) 102 | { 103 | uint32_t inu = *(reinterpret_cast(&in)); 104 | uint32_t t1; 105 | uint32_t t2; 106 | uint32_t t3; 107 | t1 = inu & 0x7fffffff; 108 | t2 = inu & 0x80000000; 109 | t3 = inu & 0x7f800000; 110 | t1 >>= 13; 111 | t2 >>= 16; 112 | t1 -= 0x1c000; 113 | t1 = (t3 < 0x38800000) ? 0 : t1; 114 | t1 = (t3 > 0x47000000) ? 0x7bff : t1; 115 | t1 = (t3 == 0 ? 0 : t1); 116 | t1 |= t2; 117 | *(reinterpret_cast(out)) = t1; 118 | } 119 | #endif 120 | 121 | } // namespace movidius_ncs_lib 122 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/device.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "movidius_ncs_lib/device.hpp" 19 | #include "movidius_ncs_lib/exception.hpp" 20 | #include "movidius_ncs_lib/exception_util.hpp" 21 | #include "movidius_ncs_lib/log.hpp" 22 | 23 | namespace movidius_ncs_lib 24 | { 25 | Device::Device(int index, LogLevel log_level) 26 | : index_(index), handle_(nullptr) 27 | { 28 | assert(index_ >= 0); 29 | setLogLevel(log_level); 30 | find(); 31 | open(); 32 | } 33 | 34 | Device::~Device() 35 | { 36 | try { 37 | close(); 38 | } catch (MvncException & e) { 39 | ROS_ERROR_STREAM("Exception caught on device[" << index_ << "], " << e.what()); 40 | } 41 | } 42 | 43 | std::string Device::getName() const 44 | { 45 | assert(handle_ != nullptr); 46 | return name_; 47 | } 48 | 49 | void Device::open() 50 | { 51 | ROS_INFO_STREAM("open device #" << index_ << " name=" << name_); 52 | int ret = mvncOpenDevice(name_.c_str(), &handle_); 53 | ExceptionUtil::tryToThrowMvncException(ret); 54 | } 55 | 56 | void Device::close() 57 | { 58 | if (handle_ == nullptr) { 59 | return; 60 | } 61 | 62 | ROS_INFO_STREAM("close device #" << index_ << " name=" << name_); 63 | int ret = mvncCloseDevice(handle_); 64 | ExceptionUtil::tryToThrowMvncException(ret); 65 | } 66 | 67 | void Device::monitorThermal() const 68 | { 69 | ThermalThrottlingLevel level = getThermalThrottlingLevel(); 70 | 71 | if (level == High) { 72 | throw MvncHighThermal(); 73 | } 74 | 75 | if (level == Aggressive) { 76 | throw MvncAggressiveThermal(); 77 | } 78 | } 79 | 80 | void Device::setLogLevel(LogLevel log_level) 81 | { 82 | int level = log_level; 83 | int ret = mvncSetGlobalOption(MVNC_LOG_LEVEL, static_cast(&level), sizeof(level)); 84 | ExceptionUtil::tryToThrowMvncException(ret); 85 | } 86 | 87 | Device::LogLevel Device::getLogLevel() 88 | { 89 | int level; 90 | unsigned int size_of_level = sizeof(level); 91 | int ret = mvncGetGlobalOption(MVNC_LOG_LEVEL, reinterpret_cast(&level), &size_of_level); 92 | ExceptionUtil::tryToThrowMvncException(ret); 93 | return static_cast(level); 94 | } 95 | 96 | Device::ThermalThrottlingLevel Device::getThermalThrottlingLevel() const 97 | { 98 | assert(handle_ != nullptr); 99 | int throttling; 100 | unsigned int size_of_throttling = sizeof(throttling); 101 | int ret = mvncGetDeviceOption(handle_, MVNC_THERMAL_THROTTLING_LEVEL, 102 | reinterpret_cast(&throttling), &size_of_throttling); 103 | ExceptionUtil::tryToThrowMvncException(ret); 104 | return static_cast(throttling); 105 | } 106 | 107 | void * Device::getHandle() 108 | { 109 | assert(handle_ != nullptr); 110 | return handle_; 111 | } 112 | 113 | void Device::find() 114 | { 115 | assert(handle_ == nullptr); 116 | char name[MVNC_MAX_NAME_SIZE]; 117 | int ret = mvncGetDeviceName(index_, name, sizeof(name)); 118 | ExceptionUtil::tryToThrowMvncException(ret); 119 | name_ = name; 120 | } 121 | } // namespace movidius_ncs_lib 122 | -------------------------------------------------------------------------------- /movidius_ncs_example/src/stream_classification.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #define LINESPACING 20 28 | 29 | class ClassificationShow : public rclcpp::Node 30 | { 31 | public: 32 | ClassificationShow() 33 | : Node("classification_show") 34 | { 35 | rclcpp::Node::SharedPtr node = std::shared_ptr(this); 36 | cam_sub_ = std::make_unique(node, "/camera/color/image_raw"); 37 | obj_sub_ = std::make_unique(node, "/movidius_ncs_stream/classified_objects"); 38 | sync_sub_ = std::make_unique(*cam_sub_, *obj_sub_, 10); 39 | sync_sub_->registerCallback(&ClassificationShow::showImage, this); 40 | } 41 | 42 | private: 43 | using camSub = message_filters::Subscriber; 44 | using objSub = message_filters::Subscriber; 45 | using sync = 46 | message_filters::TimeSynchronizer; 47 | std::unique_ptr cam_sub_; 48 | std::unique_ptr obj_sub_; 49 | std::unique_ptr sync_sub_; 50 | 51 | int getFPS() 52 | { 53 | static int fps = 0; 54 | static boost::posix_time::ptime duration_start = 55 | boost::posix_time::microsec_clock::local_time(); 56 | static int frame_cnt = 0; 57 | 58 | frame_cnt++; 59 | 60 | boost::posix_time::ptime current = boost::posix_time::microsec_clock::local_time(); 61 | boost::posix_time::time_duration msdiff = current - duration_start; 62 | 63 | if (msdiff.total_milliseconds() > 1000) { 64 | fps = frame_cnt; 65 | frame_cnt = 0; 66 | duration_start = current; 67 | } 68 | 69 | return fps; 70 | } 71 | 72 | void showImage( 73 | const sensor_msgs::msg::Image::SharedPtr & img, 74 | const object_msgs::msg::Objects::SharedPtr & objs) 75 | { 76 | cv::Mat cvImage = cv_bridge::toCvShare(img, "bgr8")->image; 77 | int cnt = 0; 78 | 79 | for (auto obj : objs->objects_vector) { 80 | std::stringstream ss; 81 | ss << obj.object_name << ": " << obj.probability * 100 << '%'; 82 | cv::putText(cvImage, ss.str(), cvPoint(LINESPACING, LINESPACING * (++cnt)), 83 | cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0)); 84 | } 85 | 86 | std::stringstream ss; 87 | int fps = getFPS(); 88 | ss << "FPS: " << fps; 89 | cv::putText(cvImage, ss.str(), cvPoint(LINESPACING, LINESPACING * (++cnt)), 90 | cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar(0, 255, 0)); 91 | 92 | cv::imshow("image_viewer", cvImage); 93 | cv::waitKey(5); 94 | } 95 | }; 96 | 97 | int main(int argc, char ** argv) 98 | { 99 | rclcpp::init(argc, argv); 100 | rclcpp::spin(std::make_shared()); 101 | rclcpp::shutdown(); 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /movidius_ncs_example/src/image_detection.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int main(int argc, char ** argv) 24 | { 25 | rclcpp::init(argc, argv); 26 | 27 | auto node = rclcpp::Node::make_shared("movidius_ncs_example"); 28 | if (argc != 2) { 29 | RCLCPP_INFO(node->get_logger(), 30 | "Usage: ros2 run movidius_ncs_example movidius_ncs_example_image_detection " 31 | ""); 32 | return -1; 33 | } 34 | 35 | auto client = 36 | node->create_client("movidius_ncs_image/detect_object"); 37 | auto request = std::make_shared(); 38 | request->image_path = argv[1]; 39 | 40 | while (!client->wait_for_service(std::chrono::seconds(1))) { 41 | if (!rclcpp::ok()) { 42 | RCLCPP_ERROR(node->get_logger(), "Interrupted while waiting for the service. Exiting."); 43 | return 1; 44 | } 45 | RCLCPP_INFO(node->get_logger(), "service not available, waiting again..."); 46 | } 47 | 48 | auto result = client->async_send_request(request); 49 | 50 | if (rclcpp::spin_until_future_complete(node, result) == 51 | rclcpp::executor::FutureReturnCode::SUCCESS) 52 | { 53 | auto srv = result.get(); 54 | cv::Mat image = cv::imread(argv[1]); 55 | int width = image.cols; 56 | int height = image.rows; 57 | for (unsigned int i = 0; i < srv->objects.objects_vector.size(); i++) { 58 | std::stringstream ss; 59 | ss << srv->objects.objects_vector[i].object.object_name << ": " << 60 | srv->objects.objects_vector[i].object.probability * 100 << "%"; 61 | RCLCPP_INFO(node->get_logger(), "%d: object: %s", i, 62 | srv->objects.objects_vector[i].object.object_name.c_str()); 63 | RCLCPP_INFO(node->get_logger(), "prob: %f", 64 | srv->objects.objects_vector[i].object.probability); 65 | RCLCPP_INFO( 66 | node->get_logger(), "location: (%d, %d, %d, %d)", 67 | srv->objects.objects_vector[i].roi.x_offset, srv->objects.objects_vector[i].roi.y_offset, 68 | srv->objects.objects_vector[i].roi.width, srv->objects.objects_vector[i].roi.height); 69 | 70 | int xmin = srv->objects.objects_vector[i].roi.x_offset; 71 | int ymin = srv->objects.objects_vector[i].roi.y_offset; 72 | int w = srv->objects.objects_vector[i].roi.width; 73 | int h = srv->objects.objects_vector[i].roi.height; 74 | 75 | int xmax = ((xmin + w) < width) ? (xmin + w) : width; 76 | int ymax = ((ymin + h) < height) ? (ymin + h) : height; 77 | 78 | cv::Point left_top = cv::Point(xmin, ymin); 79 | cv::Point right_bottom = cv::Point(xmax, ymax); 80 | cv::rectangle(image, left_top, right_bottom, cv::Scalar(0, 255, 0), 1, 8, 0); 81 | cv::rectangle(image, cv::Point(xmin, ymin), cv::Point(xmax, ymin + 20), cv::Scalar(0, 255, 0), 82 | -1); 83 | cv::putText(image, ss.str(), cv::Point(xmin + 5, ymin + 20), cv::FONT_HERSHEY_PLAIN, 1, 84 | cv::Scalar(0, 0, 255), 1); 85 | } 86 | RCLCPP_INFO(node->get_logger(), "inference time: %fms", srv->objects.inference_time_ms); 87 | cv::imshow("image_detection", image); 88 | cv::waitKey(0); 89 | } 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /movidius_ncs_stream/tests/unittest_stream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include "gtest/gtest.h" 30 | #include "rclcpp/rclcpp.hpp" 31 | #include "rclcpp/rate.hpp" 32 | #include "ament_index_cpp/get_package_prefix.hpp" 33 | #include "movidius_ncs_lib/param.hpp" 34 | 35 | bool test_pass = false; 36 | bool cnn_type_flag = false; 37 | #define MAXSIZE 100 38 | const char * buffer; 39 | 40 | template 41 | void wait_for_future( 42 | rclcpp::executor::Executor & executor, 43 | std::shared_future & future, 44 | const DurationT & timeout) 45 | { 46 | using rclcpp::executor::FutureReturnCode; 47 | rclcpp::executor::FutureReturnCode future_ret; 48 | auto start_time = std::chrono::steady_clock::now(); 49 | future_ret = executor.spin_until_future_complete(future, timeout); 50 | auto elapsed_time = std::chrono::steady_clock::now() - start_time; 51 | EXPECT_EQ(FutureReturnCode::SUCCESS, future_ret) << 52 | "the usb camera don't publish data to topic\n" << 53 | "future failed to be set after: " << 54 | std::chrono::duration_cast(elapsed_time).count() << 55 | " milliseconds\n"; 56 | } 57 | 58 | TEST(UnitTestStream, testStream) { 59 | auto node = rclcpp::Node::make_shared("movidius_ncs_stream_tests"); 60 | rmw_qos_profile_t custom_qos_profile = rmw_qos_profile_default; 61 | custom_qos_profile.depth = 5; 62 | std::promise sub_called; 63 | std::shared_future sub_called_future(sub_called.get_future()); 64 | 65 | auto callback_classify = 66 | [&sub_called](const object_msgs::msg::Objects::SharedPtr msg) -> void 67 | { 68 | test_pass = true; 69 | sub_called.set_value(true); 70 | }; 71 | 72 | auto callback_detect = 73 | [&sub_called](const object_msgs::msg::ObjectsInBoxes::SharedPtr msg) -> void 74 | { 75 | test_pass = true; 76 | sub_called.set_value(true); 77 | }; 78 | 79 | rclcpp::executors::SingleThreadedExecutor executor; 80 | executor.add_node(node); 81 | 82 | { 83 | auto sub1 = node->create_subscription( 84 | "/movidius_ncs_stream/detected_objects", 85 | callback_detect, custom_qos_profile); 86 | 87 | auto sub2 = node->create_subscription( 88 | "/movidius_ncs_stream/classified_objects", 89 | callback_classify, custom_qos_profile); 90 | 91 | executor.spin_once(std::chrono::seconds(0)); 92 | 93 | wait_for_future(executor, sub_called_future, std::chrono::seconds(10)); 94 | 95 | EXPECT_TRUE(test_pass); 96 | } 97 | } 98 | 99 | int main(int argc, char ** argv) 100 | { 101 | testing::InitGoogleTest(&argc, argv); 102 | rclcpp::init(argc, argv); 103 | auto offset = std::chrono::seconds(10); 104 | system("ros2 run composition api_composition &"); 105 | system("launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/" 106 | "launch/ncs_stream_launch.py &"); 107 | rclcpp::sleep_for(offset); 108 | int ret = RUN_ALL_TESTS(); 109 | system("killall api_composition &"); 110 | system("killall realsense_ros2_camera &"); 111 | rclcpp::shutdown(); 112 | return ret; 113 | } 114 | -------------------------------------------------------------------------------- /doc/video_detection.md: -------------------------------------------------------------------------------- 1 | ## Detection for Video 2 | This project supports multiple CNN models for detection. Please make sure you have already [set up environment](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#3-environment-setup) and [installed this project](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#4-building-and-installation) correctly. You can refer to the following links for your interested models then. 3 | #### [1 CNN Models](#1-cnn-models-1) 4 | * [MobileNet_SSD](#mobilenet_ssd) 5 | * [TinyYolo_V1](#tinyyolo_v1) 6 | #### [2 Run with Other ROS Supported Cameras](#2-run-with-other-ros-supported-cameras-1) 7 | #### [3 Other Arguments](#3-other-arguments-1) 8 | ---------------------------------- 9 | 10 | ### 1 CNN Models 11 | * #### MobileNet_SSD 12 | Compile NCS graph. 13 | ```Shell 14 | cd /opt/movidius/ncappzoo/caffe/SSD_MobileNet 15 | make 16 | ``` 17 | Launch video streaming nodelet. 18 | - Option 1: RealSense 19 | ```Shell 20 | # Choose CNN model 21 | cd ~/ros2_ws 22 | echo -e "param_file: mobilenetssd.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 23 | ament build 24 | source install/local_setup.bash 25 | # Terminal 1, run realsense camera 26 | realsense_ros2_camera 27 | # Terminal 2, run video streaming composition manager 28 | ros2 run composition api_composition 29 | # Terminal 3, launch video streaming composistion 30 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 31 | ``` 32 | - Option 2: Astra 33 | ```Shell 34 | # Choose CNN model 35 | cd ~/ros2_ws 36 | echo -e "param_file: mobilenetssd.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 37 | ament build 38 | source install/local_setup.bash 39 | # Terminal 1, run astra camera 40 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 41 | # Terminal 2, run video streaming composition manager 42 | ros2 run composition api_composition 43 | # Terminal 3, launch video streaming composistion 44 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 45 | ``` 46 | Launch image viewer to show the classification result on another console. 47 | ```Shell 48 | ros2 run movidius_ncs_example movidius_ncs_example_stream_detection 49 | ``` 50 | * #### TinyYolo_V1 51 | Compile NCS graph. 52 | ```Shell 53 | cd /opt/movidius/ncappzoo/caffe/TinyYolo 54 | make 55 | ``` 56 | Launch video streaming nodelet. 57 | - Option 1: RealSense 58 | ```Shell 59 | # Choose CNN model 60 | cd ~/ros2_ws 61 | echo -e "param_file: tinyyolo_v1.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 62 | ament build 63 | source install/local_setup.bash 64 | # Terminal 1, run realsense camera 65 | realsense_ros2_camera 66 | # Terminal 2, run video streaming composition manager 67 | ros2 run composition api_composition 68 | # Terminal 3, launch video streaming composistion 69 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 70 | ``` 71 | - Option 2: Astra 72 | ```Shell 73 | # Choose CNN model 74 | cd ~/ros2_ws 75 | echo -e "param_file: tinyyolo_v1.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 76 | ament build 77 | source install/local_setup.bash 78 | # Terminal 1, run astra camera 79 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 80 | # Terminal 2, run video streaming composition manager 81 | ros2 run composition api_composition 82 | # Terminal 3, launch video streaming composistion 83 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 84 | ``` 85 | Launch image viewer to show the classification result on another console. 86 | ```Shell 87 | ros2 run movidius_ncs_example movidius_ncs_example_stream_detection 88 | ``` 89 | ### 2 Run with Other ROS Supported Cameras 90 | TODO 91 | ### 3 Other Arguments 92 | |Arguments|Description|Default Value|Valid Values| 93 | |:-|:-|:-|:-| 94 | |device_index|ncs device index|0|0~N-1(N is the maximum number of inserted NCS devices)| 95 | |log_level|ncs log level|0|0:Nothing / 1:Errors / 2:Verbose| 96 | |cnn_type|indicate different cnn models|googlenet|mobilenetssd / tinyyolo_v1| 97 | -------------------------------------------------------------------------------- /movidius_ncs_lib/include/movidius_ncs_lib/exception.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MOVIDIUS_NCS_LIB__EXCEPTION_HPP_ 16 | #define MOVIDIUS_NCS_LIB__EXCEPTION_HPP_ 17 | 18 | #include 19 | #include 20 | 21 | namespace movidius_ncs_lib 22 | { 23 | struct NCSException : public std::exception 24 | { 25 | }; 26 | 27 | struct MvncException : public NCSException 28 | { 29 | explicit MvncException(const std::string & msg) 30 | : msg_(msg) 31 | { 32 | } 33 | 34 | const char * what() const noexcept 35 | { 36 | return msg_.c_str(); 37 | } 38 | 39 | private: 40 | const std::string msg_; 41 | }; 42 | 43 | struct MvncBusy : public MvncException 44 | { 45 | explicit MvncBusy(const std::string & msg) 46 | : MvncException(msg) 47 | { 48 | } 49 | }; 50 | 51 | struct MvncError : public MvncException 52 | { 53 | explicit MvncError(const std::string & msg) 54 | : MvncException(msg) 55 | { 56 | } 57 | }; 58 | 59 | struct MvncOutOfMemory : public MvncException 60 | { 61 | explicit MvncOutOfMemory(const std::string & msg) 62 | : MvncException(msg) 63 | { 64 | } 65 | }; 66 | 67 | struct MvncDeviceNotFound : public MvncException 68 | { 69 | explicit MvncDeviceNotFound(const std::string & msg) 70 | : MvncException(msg) 71 | { 72 | } 73 | }; 74 | 75 | struct MvncInvalidParameters : public MvncException 76 | { 77 | explicit MvncInvalidParameters(const std::string & msg) 78 | : MvncException(msg) 79 | { 80 | } 81 | }; 82 | 83 | struct MvncTimeout : public MvncException 84 | { 85 | explicit MvncTimeout(const std::string & msg) 86 | : MvncException(msg) 87 | { 88 | } 89 | }; 90 | 91 | struct MvncMvCmdNotFound : public MvncException 92 | { 93 | explicit MvncMvCmdNotFound(const std::string & msg) 94 | : MvncException(msg) 95 | { 96 | } 97 | }; 98 | 99 | struct MvncNoData : public MvncException 100 | { 101 | explicit MvncNoData(const std::string & msg) 102 | : MvncException(msg) 103 | { 104 | } 105 | }; 106 | 107 | struct MvncGone : public MvncException 108 | { 109 | explicit MvncGone(const std::string & msg) 110 | : MvncException(msg) 111 | { 112 | } 113 | }; 114 | 115 | struct MvncUnsupportedGraphFile : public MvncException 116 | { 117 | explicit MvncUnsupportedGraphFile(const std::string & msg) 118 | : MvncException(msg) 119 | { 120 | } 121 | }; 122 | 123 | struct MvncMyriadError : public MvncException 124 | { 125 | explicit MvncMyriadError(const std::string & msg) 126 | : MvncException(msg) 127 | { 128 | } 129 | }; 130 | 131 | struct MvncThermalException : public NCSException 132 | { 133 | virtual const char * what() const noexcept = 0; 134 | }; 135 | 136 | struct MvncHighThermal : public MvncThermalException 137 | { 138 | const char * what() const noexcept; 139 | }; 140 | 141 | struct MvncAggressiveThermal : public MvncThermalException 142 | { 143 | const char * what() const noexcept; 144 | }; 145 | 146 | struct NCSGraphException : public NCSException 147 | { 148 | virtual const char * what() const noexcept = 0; 149 | }; 150 | 151 | struct NCSGraphFileError : public NCSGraphException 152 | { 153 | const char * what() const noexcept; 154 | }; 155 | 156 | struct NCSMeanAndStddevError : public NCSGraphException 157 | { 158 | const char * what() const noexcept; 159 | }; 160 | 161 | struct NCSInputSizeFileError : public NCSGraphException 162 | { 163 | const char * what() const noexcept; 164 | }; 165 | 166 | struct NCSInputSizeError : public NCSGraphException 167 | { 168 | const char * what() const noexcept; 169 | }; 170 | 171 | struct NCSLoadCategoriesError : public NCSGraphException 172 | { 173 | const char * what() const noexcept; 174 | }; 175 | } // namespace movidius_ncs_lib 176 | #endif // MOVIDIUS_NCS_LIB__EXCEPTION_HPP_ 177 | -------------------------------------------------------------------------------- /movidius_ncs_example/src/stream_detection.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #define LINESPACING 20 28 | 29 | class DetectionShow : public rclcpp::Node 30 | { 31 | public: 32 | DetectionShow() 33 | : Node("detection_show") 34 | { 35 | rclcpp::Node::SharedPtr node = std::shared_ptr(this); 36 | cam_sub_ = std::make_unique(node, "/camera/color/image_raw"); 37 | obj_sub_ = std::make_unique(node, "/movidius_ncs_stream/detected_objects"); 38 | sync_sub_ = std::make_unique(*cam_sub_, *obj_sub_, 10); 39 | sync_sub_->registerCallback(&DetectionShow::showImage, this); 40 | } 41 | 42 | private: 43 | using camSub = message_filters::Subscriber; 44 | using objSub = message_filters::Subscriber; 45 | using sync = 46 | message_filters::TimeSynchronizer; 47 | std::unique_ptr cam_sub_; 48 | std::unique_ptr obj_sub_; 49 | std::unique_ptr sync_sub_; 50 | 51 | int getFPS() 52 | { 53 | static int fps = 0; 54 | static boost::posix_time::ptime duration_start = 55 | boost::posix_time::microsec_clock::local_time(); 56 | static int frame_cnt = 0; 57 | 58 | frame_cnt++; 59 | 60 | boost::posix_time::ptime current = boost::posix_time::microsec_clock::local_time(); 61 | boost::posix_time::time_duration msdiff = current - duration_start; 62 | 63 | if (msdiff.total_milliseconds() > 1000) { 64 | fps = frame_cnt; 65 | frame_cnt = 0; 66 | duration_start = current; 67 | } 68 | 69 | return fps; 70 | } 71 | 72 | void showImage( 73 | const sensor_msgs::msg::Image::SharedPtr & img, 74 | const object_msgs::msg::ObjectsInBoxes::SharedPtr & objs) 75 | { 76 | cv::Mat cvImage = cv_bridge::toCvShare(img, "bgr8")->image; 77 | int width = img->width; 78 | int height = img->height; 79 | 80 | for (auto obj : objs->objects_vector) { 81 | std::stringstream ss; 82 | ss << obj.object.object_name << ": " << obj.object.probability * 100 << '%'; 83 | 84 | int xmin = obj.roi.x_offset; 85 | int ymin = obj.roi.y_offset; 86 | int w = obj.roi.width; 87 | int h = obj.roi.height; 88 | 89 | int xmax = ((xmin + w) < width) ? (xmin + w) : width; 90 | int ymax = ((ymin + h) < height) ? (ymin + h) : height; 91 | 92 | cv::Point left_top = cv::Point(xmin, ymin); 93 | cv::Point right_bottom = cv::Point(xmax, ymax); 94 | cv::rectangle(cvImage, left_top, right_bottom, cv::Scalar(0, 255, 0), 1, 8, 0); 95 | cv::rectangle(cvImage, cvPoint(xmin, ymin), cvPoint(xmax, ymin + 20), cv::Scalar(0, 255, 0), 96 | -1); 97 | cv::putText(cvImage, ss.str(), cvPoint(xmin + 5, ymin + 20), cv::FONT_HERSHEY_PLAIN, 1, 98 | cv::Scalar(0, 0, 255), 1); 99 | } 100 | std::stringstream ss; 101 | int fps = getFPS(); 102 | ss << "FPS: " << fps; 103 | cv::putText(cvImage, ss.str(), cvPoint(LINESPACING, LINESPACING), cv::FONT_HERSHEY_PLAIN, 1, 104 | cv::Scalar(0, 255, 0)); 105 | 106 | cv::imshow("image_viewer", cvImage); 107 | cv::waitKey(5); 108 | } 109 | }; 110 | 111 | int main(int argc, char ** argv) 112 | { 113 | rclcpp::init(argc, argv); 114 | rclcpp::spin(std::make_shared()); 115 | rclcpp::shutdown(); 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /movidius_ncs_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5) 16 | project(movidius_ncs_image) 17 | 18 | find_package(ament_cmake REQUIRED) 19 | find_package(ament_index_cpp REQUIRED) 20 | find_package(rclcpp REQUIRED) 21 | find_package(sensor_msgs REQUIRED) 22 | find_package(object_msgs REQUIRED) 23 | find_package(movidius_ncs_lib REQUIRED) 24 | find_package(OpenCV REQUIRED) 25 | 26 | include_directories(include) 27 | 28 | add_executable(${PROJECT_NAME} src/ncs_server.cpp) 29 | ament_target_dependencies(${PROJECT_NAME} 30 | "ament_index_cpp" 31 | "rclcpp" 32 | "sensor_msgs" 33 | "movidius_ncs_lib" 34 | "object_msgs" 35 | "OpenCV") 36 | 37 | # Flags 38 | if(UNIX OR APPLE) 39 | # Linker flags. 40 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 41 | # GCC specific flags. ICC is compatible with them. 42 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now") 43 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now") 44 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 45 | # In Clang, -z flags are not compatible, they need to be passed to linker via -Wl. 46 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 47 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 48 | endif() 49 | 50 | # Compiler flags. 51 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") 52 | # GCC specific flags. 53 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9) 54 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong") 55 | else() 56 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 57 | endif() 58 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 59 | # Clang is compatbile with some of the flags. 60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 61 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 62 | # Same as above, with exception that ICC compilation crashes with -fPIE option, even 63 | # though it uses -pie linker option that require -fPIE during compilation. Checksec 64 | # shows that it generates correct PIE anyway if only -pie is provided. 65 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") 66 | endif() 67 | 68 | # Generic flags. 69 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-operator-names -Wformat -Wformat-security -Wall") 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 71 | # Dot not forward c++14 flag to GPU beucause it is not supported 72 | set(CUDA_PROPAGATE_HOST_FLAGS OFF) 73 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") 74 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") 75 | endif() 76 | 77 | install(DIRECTORY include/${PROJECT_NAME}/ 78 | DESTINATION include/${PROJECT_NAME}) 79 | 80 | install(TARGETS ${PROJECT_NAME} 81 | ARCHIVE DESTINATION lib 82 | LIBRARY DESTINATION lib 83 | RUNTIME DESTINATION lib/${PROJECT_NAME}) 84 | 85 | install(TARGETS ${PROJECT_NAME} 86 | RUNTIME DESTINATION bin 87 | ) 88 | 89 | if(BUILD_TESTING) 90 | find_package(ament_lint_auto REQUIRED) 91 | find_package(rclcpp REQUIRED) 92 | find_package(std_msgs REQUIRED) 93 | find_package(object_msgs REQUIRED) 94 | find_package(movidius_ncs_lib REQUIRED) 95 | ament_lint_auto_find_test_dependencies() 96 | 97 | ament_add_gtest(unittest_image tests/unittest_image.cpp) 98 | if(TARGET unittest_image) 99 | target_include_directories(unittest_image PUBLIC 100 | ${${PROJECT_NAME}_INCLUDE_DIRS} 101 | ) 102 | ament_target_dependencies(unittest_image 103 | rclcpp 104 | object_msgs 105 | ament_index_cpp 106 | movidius_ncs_lib) 107 | endif() 108 | endif() 109 | 110 | ament_package() 111 | -------------------------------------------------------------------------------- /movidius_ncs_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5) 16 | project(movidius_ncs_example) 17 | 18 | find_package(ament_cmake REQUIRED) 19 | find_package(rclcpp REQUIRED) 20 | find_package(sensor_msgs REQUIRED) 21 | find_package(object_msgs REQUIRED) 22 | find_package(OpenCV REQUIRED) 23 | find_package(message_filters REQUIRED) 24 | find_package(cv_bridge REQUIRED) 25 | 26 | add_executable(${PROJECT_NAME}_image_detection src/image_detection.cpp) 27 | ament_target_dependencies(${PROJECT_NAME}_image_detection 28 | "rclcpp" 29 | "object_msgs" 30 | "OpenCV") 31 | 32 | add_executable(${PROJECT_NAME}_image_classification src/image_classification.cpp) 33 | ament_target_dependencies(${PROJECT_NAME}_image_classification 34 | "rclcpp" 35 | "object_msgs" 36 | "OpenCV") 37 | 38 | add_executable(${PROJECT_NAME}_stream_detection src/stream_detection.cpp) 39 | ament_target_dependencies(${PROJECT_NAME}_stream_detection 40 | "rclcpp" 41 | "object_msgs" 42 | "OpenCV" 43 | "message_filters" 44 | "cv_bridge") 45 | 46 | add_executable(${PROJECT_NAME}_stream_classification src/stream_classification.cpp) 47 | ament_target_dependencies(${PROJECT_NAME}_stream_classification 48 | "rclcpp" 49 | "object_msgs" 50 | "OpenCV" 51 | "message_filters" 52 | "cv_bridge") 53 | 54 | if(BUILD_TESTING) 55 | find_package(ament_lint_auto REQUIRED) 56 | ament_lint_auto_find_test_dependencies() 57 | endif() 58 | 59 | # Flags 60 | if(UNIX OR APPLE) 61 | # Linker flags. 62 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 63 | # GCC specific flags. ICC is compatible with them. 64 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now") 65 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now") 66 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 67 | # In Clang, -z flags are not compatible, they need to be passed to linker via -Wl. 68 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 69 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 70 | endif() 71 | 72 | # Compiler flags. 73 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") 74 | # GCC specific flags. 75 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9) 76 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong") 77 | else() 78 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 79 | endif() 80 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 81 | # Clang is compatbile with some of the flags. 82 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 83 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 84 | # Same as above, with exception that ICC compilation crashes with -fPIE option, even 85 | # though it uses -pie linker option that require -fPIE during compilation. Checksec 86 | # shows that it generates correct PIE anyway if only -pie is provided. 87 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") 88 | endif() 89 | 90 | # Generic flags. 91 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-operator-names -Wformat -Wformat-security -Wall") 92 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 93 | # Dot not forward c++14 flag to GPU beucause it is not supported 94 | set(CUDA_PROPAGATE_HOST_FLAGS OFF) 95 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") 96 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") 97 | endif() 98 | 99 | install(TARGETS ${PROJECT_NAME}_image_detection 100 | ${PROJECT_NAME}_image_classification 101 | ${PROJECT_NAME}_stream_detection 102 | ${PROJECT_NAME}_stream_classification 103 | ARCHIVE DESTINATION lib 104 | LIBRARY DESTINATION lib 105 | RUNTIME DESTINATION lib/${PROJECT_NAME}) 106 | 107 | ament_package() 108 | -------------------------------------------------------------------------------- /movidius_ncs_stream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5) 16 | project(movidius_ncs_stream) 17 | 18 | find_package(ament_cmake REQUIRED) 19 | find_package(ament_index_cpp REQUIRED) 20 | find_package(rclcpp REQUIRED) 21 | find_package(class_loader REQUIRED) 22 | find_package(object_msgs REQUIRED) 23 | find_package(movidius_ncs_lib REQUIRED) 24 | find_package(yaml_cpp_vendor REQUIRED) 25 | find_package(sensor_msgs REQUIRED) 26 | find_package(OpenCV REQUIRED) 27 | find_package(cv_bridge REQUIRED) 28 | 29 | include_directories(include 30 | ${yaml_cpp_vendor_DIR}/../../../opt/yaml_cpp_vendor/include) 31 | 32 | add_library(${PROJECT_NAME} SHARED 33 | src/ncs_composition.cpp) 34 | ament_target_dependencies(${PROJECT_NAME} 35 | "ament_index_cpp" 36 | "class_loader" 37 | "rclcpp" 38 | "yaml_cpp_vendor" 39 | "sensor_msgs" 40 | "movidius_ncs_lib" 41 | "object_msgs" 42 | "OpenCV" 43 | "cv_bridge") 44 | rclcpp_register_node_plugins(${PROJECT_NAME} "movidius_ncs_stream::NCSComposition") 45 | 46 | # Flags 47 | if(UNIX OR APPLE) 48 | # Linker flags. 49 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 50 | # GCC specific flags. ICC is compatible with them. 51 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now") 52 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now") 53 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 54 | # In Clang, -z flags are not compatible, they need to be passed to linker via -Wl. 55 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 56 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 57 | endif() 58 | 59 | # Compiler flags. 60 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") 61 | # GCC specific flags. 62 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9) 63 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong") 64 | else() 65 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 66 | endif() 67 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 68 | # Clang is compatbile with some of the flags. 69 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 70 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 71 | # Same as above, with exception that ICC compilation crashes with -fPIE option, even 72 | # though it uses -pie linker option that require -fPIE during compilation. Checksec 73 | # shows that it generates correct PIE anyway if only -pie is provided. 74 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") 75 | endif() 76 | 77 | # Generic flags. 78 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-operator-names -Wformat -Wformat-security -Wall") 79 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 80 | # Dot not forward c++14 flag to GPU beucause it is not supported 81 | set(CUDA_PROPAGATE_HOST_FLAGS OFF) 82 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") 83 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") 84 | endif() 85 | 86 | install(DIRECTORY include/${PROJECT_NAME}/ 87 | DESTINATION include 88 | ) 89 | 90 | install(TARGETS ${PROJECT_NAME} 91 | ARCHIVE DESTINATION lib 92 | LIBRARY DESTINATION lib 93 | RUNTIME DESTINATION bin 94 | ) 95 | 96 | if(BUILD_TESTING) 97 | find_package(ament_lint_auto REQUIRED) 98 | find_package(rclcpp REQUIRED) 99 | find_package(std_msgs REQUIRED) 100 | find_package(object_msgs REQUIRED) 101 | find_package(movidius_ncs_lib REQUIRED) 102 | find_package(ament_index_cpp REQUIRED) 103 | ament_lint_auto_find_test_dependencies() 104 | 105 | ament_add_gtest(unittest_stream tests/unittest_stream.cpp) 106 | if(TARGET unittest_stream) 107 | target_include_directories(unittest_stream PUBLIC 108 | ${${PROJECT_NAME}_INCLUDE_DIRS} 109 | ) 110 | ament_target_dependencies(unittest_stream 111 | rclcpp 112 | object_msgs 113 | ament_index_cpp 114 | movidius_ncs_lib) 115 | endif() 116 | endif() 117 | 118 | ament_package() 119 | -------------------------------------------------------------------------------- /movidius_ncs_lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2017 Intel Corporation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.5) 16 | project(movidius_ncs_lib) 17 | 18 | find_package(ament_cmake REQUIRED) 19 | find_package(OpenCV REQUIRED) 20 | find_package(yaml_cpp_vendor REQUIRED) 21 | find_package(rclcpp REQUIRED) 22 | 23 | find_path(MVNC_HEADER_FILE 24 | mvnc.h 25 | PATHS ENV ROS_ROOT) 26 | if(NOT MVNC_HEADER_FILE) 27 | message(FATAL_ERROR "Can't find mvnc.h, please install Movidius NCS SDK according to 28 | https://github.com/movidius/ncsdk") 29 | endif() 30 | 31 | include_directories(include 32 | ${yaml_cpp_vendor_DIR}/../../../opt/yaml_cpp_vendor/include) 33 | 34 | add_library(${PROJECT_NAME} SHARED 35 | src/ncs.cpp 36 | src/device.cpp 37 | src/exception.cpp 38 | src/exception_util.cpp 39 | src/graph.cpp 40 | src/tensor.cpp 41 | src/result.cpp 42 | src/param.cpp) 43 | target_link_libraries(${PROJECT_NAME} 44 | mvnc) 45 | 46 | ament_target_dependencies(${PROJECT_NAME} 47 | "yaml_cpp_vendor" 48 | "OpenCV") 49 | 50 | ament_export_include_directories(include) 51 | ament_export_libraries(${PROJECT_NAME}) 52 | 53 | # Flags 54 | if(UNIX OR APPLE) 55 | # Linker flags. 56 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 57 | # GCC specific flags. ICC is compatible with them. 58 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z noexecstack -z relro -z now") 59 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now") 60 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 61 | # In Clang, -z flags are not compatible, they need to be passed to linker via -Wl. 62 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 63 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") 64 | endif() 65 | 66 | # Compiler flags. 67 | if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") 68 | # GCC specific flags. 69 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9 OR CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.9) 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector-strong") 71 | else() 72 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 73 | endif() 74 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") 75 | # Clang is compatbile with some of the flags. 76 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -fstack-protector") 77 | elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel") 78 | # Same as above, with exception that ICC compilation crashes with -fPIE option, even 79 | # though it uses -pie linker option that require -fPIE during compilation. Checksec 80 | # shows that it generates correct PIE anyway if only -pie is provided. 81 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector") 82 | endif() 83 | 84 | # Generic flags. 85 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-operator-names -Wformat -Wformat-security -Wall") 86 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") 87 | # Dot not forward c++14 flag to GPU beucause it is not supported 88 | set(CUDA_PROPAGATE_HOST_FLAGS OFF) 89 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_FORTIFY_SOURCE=2") 90 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") 91 | endif() 92 | 93 | # Add x86 intrinsic compiler support 94 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") 95 | execute_process( 96 | COMMAND bash -c "lscpu | grep -qi flags | grep -qi flags | grep -qi f16c" 97 | RESULT_VARIABLE SUPPORT_F16C) 98 | if(SUPPORT_F16C EQUAL 0) 99 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mf16c") 100 | add_definitions(-DSUPPORT_MF16C) 101 | endif() 102 | 103 | execute_process( 104 | COMMAND bash -c "lscpu | grep -qi flags | grep -qi flags | grep -qi sse4_1" 105 | RESULT_VARIABLE SUPPORT_SSE41) 106 | if(SUPPORT_SSE41 EQUAL 0) 107 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1") 108 | endif() 109 | 110 | # Install nodelet library 111 | install(TARGETS ${PROJECT_NAME} 112 | ARCHIVE DESTINATION lib 113 | LIBRARY DESTINATION lib 114 | RUNTIME DESTINATION bin) 115 | 116 | # Install header files 117 | install(DIRECTORY include/ 118 | DESTINATION include) 119 | 120 | ament_export_include_directories(include) 121 | ament_export_libraries(${PROJECT_NAME}) 122 | 123 | if(BUILD_TESTING) 124 | find_package(ament_lint_auto REQUIRED) 125 | ament_lint_auto_find_test_dependencies() 126 | ament_add_gtest(unittest_environment tests/unittest_environment.cpp) 127 | if(TARGET unittest_environment) 128 | target_include_directories(unittest_environment PUBLIC 129 | ${${PROJECT_NAME}_INCLUDE_DIRS} 130 | ) 131 | ament_target_dependencies(unittest_environment 132 | rclcpp) 133 | endif() 134 | endif() 135 | 136 | ament_package() 137 | -------------------------------------------------------------------------------- /movidius_ncs_image/tests/unittest_image.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "gtest/gtest.h" 25 | #include "rclcpp/rclcpp.hpp" 26 | #include "rclcpp/exceptions.hpp" 27 | #include "ament_index_cpp/get_resource.hpp" 28 | #include "movidius_ncs_lib/param.hpp" 29 | 30 | bool cnn_type_flag = false; 31 | 32 | void getCnnType() 33 | { 34 | std::string content; 35 | std::string prefix_path; 36 | std::string line; 37 | std::string param_file; 38 | ament_index_cpp::get_resource("packages", "movidius_ncs_launch", content, &prefix_path); 39 | std::ifstream fin(prefix_path + "/share/movidius_ncs_launch/config/default.yaml"); 40 | if (std::getline(fin, line)) { 41 | param_file = line.substr(line.find(":") + 1); 42 | } 43 | auto param_ = std::make_shared(); 44 | param_file.erase(param_file.begin(), 45 | std::find_if(param_file.begin(), param_file.end(), 46 | std::not1(std::ptr_fun(std::isspace)))); 47 | if (param_->loadParamFromYAML(prefix_path + 48 | "/share/movidius_ncs_launch/config/" + 49 | param_file)) 50 | { 51 | if (!param_->cnn_type_.compare("alexnet") || 52 | !param_->cnn_type_.compare("googlenet") || 53 | !param_->cnn_type_.compare("inception_v1") || 54 | !param_->cnn_type_.compare("inception_v2") || 55 | !param_->cnn_type_.compare("inception_v3") || 56 | !param_->cnn_type_.compare("inception_v4") || 57 | !param_->cnn_type_.compare("mobilenet") || 58 | !param_->cnn_type_.compare("squeezenet")) 59 | { 60 | cnn_type_flag = false; 61 | } else { 62 | cnn_type_flag = true; 63 | } 64 | } 65 | } 66 | 67 | std::string generate_file_path(std::string path) 68 | { 69 | std::string base_path = __FILE__; 70 | const std::string filename = "movidius_ncs_image/tests/unittest_image.cpp"; 71 | base_path = base_path.substr(0, base_path.length() - filename.length() - 1); 72 | return base_path + "/" + path; 73 | } 74 | 75 | TEST(UnitTestImage, testImage) { 76 | if (cnn_type_flag) { 77 | auto node = rclcpp::Node::make_shared("movidius_ncs_image_tests"); 78 | 79 | auto client = node->create_client("movidius_ncs_image/" 80 | "detect_object"); 81 | auto request = std::make_shared(); 82 | 83 | std::string buffer = generate_file_path("data/images/bicycle.jpg"); 84 | request->image_path = buffer; 85 | 86 | if (!client->wait_for_service(std::chrono::seconds(20))) { 87 | ASSERT_TRUE(false) << "service not available after waiting"; 88 | } 89 | 90 | auto result = client->async_send_request(request); 91 | 92 | auto ret = rclcpp::spin_until_future_complete(node, result, std::chrono::seconds(5)); 93 | EXPECT_EQ(ret, rclcpp::executor::FutureReturnCode::SUCCESS); 94 | 95 | auto srv = result.get(); 96 | 97 | EXPECT_TRUE(srv->objects.objects_vector.size()); 98 | EXPECT_EQ(srv->objects.objects_vector[0].object.object_name, "bicycle"); 99 | EXPECT_TRUE(srv->objects.objects_vector[0].roi.x_offset > 130 && 100 | srv->objects.objects_vector[0].roi.x_offset < 150 && 101 | srv->objects.objects_vector[0].roi.y_offset > 90 && 102 | srv->objects.objects_vector[0].roi.y_offset < 110 && 103 | srv->objects.objects_vector[0].roi.width > 410 && 104 | srv->objects.objects_vector[0].roi.width < 470 && 105 | srv->objects.objects_vector[0].roi.height > 340 && 106 | srv->objects.objects_vector[0].roi.height < 360); 107 | } else { 108 | auto node = rclcpp::Node::make_shared("movidius_ncs_image_tests"); 109 | 110 | auto client = node->create_client("movidius_ncs_image/" 111 | "classify_object"); 112 | auto request = std::make_shared(); 113 | request->image_path = "/opt/movidius/ncappzoo/data/images/cat.jpg"; 114 | 115 | if (!client->wait_for_service(std::chrono::seconds(20))) { 116 | ASSERT_TRUE(false) << "service not available after waiting"; 117 | } 118 | 119 | auto result = client->async_send_request(request); 120 | // Wait for the result. 121 | auto ret = rclcpp::spin_until_future_complete(node, result, std::chrono::seconds(5)); 122 | EXPECT_EQ(ret, rclcpp::executor::FutureReturnCode::SUCCESS); 123 | 124 | auto srv = result.get(); 125 | 126 | EXPECT_TRUE(srv->objects.objects_vector.size()); 127 | EXPECT_TRUE(srv->objects.objects_vector[0].object_name.find("cat") != std::string::npos); 128 | } 129 | } 130 | 131 | int main(int argc, char ** argv) 132 | { 133 | rclcpp::init(argc, argv); 134 | testing::InitGoogleTest(&argc, argv); 135 | system("movidius_ncs_image &"); 136 | getCnnType(); 137 | int ret = RUN_ALL_TESTS(); 138 | system("killall movidius_ncs_image &"); 139 | rclcpp::shutdown(); 140 | return ret; 141 | } 142 | -------------------------------------------------------------------------------- /movidius_ncs_image/src/ncs_server.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "ament_index_cpp/get_resource.hpp" 23 | #include "movidius_ncs_image/ncs_server.hpp" 24 | #include "movidius_ncs_lib/exception.hpp" 25 | #include "movidius_ncs_lib/exception_util.hpp" 26 | 27 | using movidius_ncs_lib::ClassificationResultPtr; 28 | using movidius_ncs_lib::DetectionResultPtr; 29 | using movidius_ncs_lib::Device; 30 | 31 | namespace movidius_ncs_image 32 | { 33 | NCSServer::NCSServer(const std::string & service_name) 34 | : Node("movidius_ncs_image"), ncs_handle_(nullptr), param_(nullptr) 35 | { 36 | try { 37 | std::string content; 38 | std::string prefix_path; 39 | std::string line; 40 | std::string param_file; 41 | ament_index_cpp::get_resource("packages", "movidius_ncs_launch", content, &prefix_path); 42 | std::ifstream fin(prefix_path + "/share/movidius_ncs_launch/config/default.yaml"); 43 | if (std::getline(fin, line)) { 44 | if (line.find("param_file") != std::string::npos) { 45 | param_file = line.substr(line.find(":") + 1); 46 | } 47 | } 48 | if (param_file.empty()) { 49 | RCLCPP_ERROR(this->get_logger(), "param_file not set, please check default.yaml"); 50 | rclcpp::shutdown(); 51 | } else { 52 | param_ = std::make_shared(); 53 | param_file.erase(param_file.begin(), 54 | std::find_if(param_file.begin(), param_file.end(), 55 | std::not1(std::ptr_fun(std::isspace)))); 56 | if (param_->loadParamFromYAML(prefix_path + "/share/movidius_ncs_launch/config/" + 57 | param_file) && param_->validateParam()) 58 | { 59 | init(service_name); 60 | } else { 61 | rclcpp::shutdown(); 62 | } 63 | } 64 | } catch (movidius_ncs_lib::MvncException & e) { 65 | RCLCPP_ERROR(this->get_logger(), "Error: %s", e.what()); 66 | rclcpp::shutdown(); 67 | } catch (...) { 68 | RCLCPP_ERROR(this->get_logger(), "exception caught while starting NCSServer"); 69 | rclcpp::shutdown(); 70 | } 71 | } 72 | 73 | void NCSServer::init(const std::string & service_name) 74 | { 75 | RCLCPP_DEBUG(this->get_logger(), "NCSServer onInit"); 76 | std::vector mean = {param_->channel1_mean_, param_->channel2_mean_, 77 | param_->channel3_mean_}; 78 | ncs_handle_ = std::make_shared( 79 | param_->device_index_, static_cast(param_->log_level_), param_->cnn_type_, 80 | param_->graph_file_path_, param_->category_file_path_, param_->network_dimension_, mean, 81 | param_->scale_, param_->top_n_); 82 | 83 | if (!param_->cnn_type_.compare("alexnet") || !param_->cnn_type_.compare("googlenet") || 84 | !param_->cnn_type_.compare("inception_v1") || !param_->cnn_type_.compare("inception_v2") || 85 | !param_->cnn_type_.compare("inception_v3") || !param_->cnn_type_.compare("inception_v4") || 86 | !param_->cnn_type_.compare("mobilenet") || !param_->cnn_type_.compare("squeezenet")) 87 | { 88 | service_classify_ = create_service( 89 | service_name + "/classify_object", 90 | std::bind(&NCSServer::cbClassifyObject, this, std::placeholders::_1, std::placeholders::_2, 91 | std::placeholders::_3)); 92 | } else { 93 | service_detect_ = create_service( 94 | service_name + "/detect_object", 95 | std::bind(&NCSServer::cbDetectObject, this, std::placeholders::_1, std::placeholders::_2, 96 | std::placeholders::_3)); 97 | } 98 | } 99 | 100 | void NCSServer::cbClassifyObject( 101 | const std::shared_ptr request_header, 102 | const std::shared_ptr request, 103 | std::shared_ptr response) 104 | { 105 | RCLCPP_WARN(this->get_logger(), "cbClassifyObject"); 106 | cv::Mat imageData = cv::imread(request->image_path); 107 | ncs_handle_->loadTensor(imageData); 108 | ncs_handle_->classify(); 109 | ClassificationResultPtr result = ncs_handle_->getClassificationResult(); 110 | 111 | if (result != nullptr) { 112 | for (auto item : result->items) { 113 | object_msgs::msg::Object obj; 114 | obj.object_name = item.category; 115 | obj.probability = item.probability; 116 | response->objects.objects_vector.push_back(obj); 117 | } 118 | 119 | response->objects.inference_time_ms = result->time_taken; 120 | } 121 | } 122 | 123 | void NCSServer::cbDetectObject( 124 | const std::shared_ptr request_header, 125 | const std::shared_ptr request, 126 | std::shared_ptr response) 127 | { 128 | RCLCPP_WARN(this->get_logger(), "cbDetectObject"); 129 | cv::Mat imageData = cv::imread(request->image_path); 130 | ncs_handle_->loadTensor(imageData); 131 | ncs_handle_->detect(); 132 | DetectionResultPtr result = ncs_handle_->getDetectionResult(); 133 | 134 | if (result != nullptr) { 135 | for (auto item : result->items_in_boxes) { 136 | object_msgs::msg::ObjectInBox obj; 137 | obj.object.object_name = item.item.category; 138 | obj.object.probability = item.item.probability; 139 | obj.roi.x_offset = item.bbox.x; 140 | obj.roi.y_offset = item.bbox.y; 141 | obj.roi.width = item.bbox.width; 142 | obj.roi.height = item.bbox.height; 143 | response->objects.objects_vector.push_back(obj); 144 | } 145 | 146 | response->objects.inference_time_ms = result->time_taken; 147 | } 148 | } 149 | } // namespace movidius_ncs_image 150 | 151 | int main(int argc, char ** argv) 152 | { 153 | rclcpp::init(argc, argv); 154 | 155 | try { 156 | auto node = std::make_shared("movidius_ncs_image"); 157 | rclcpp::spin(node); 158 | } catch (...) { 159 | std::cout << "[ERROR] [movidius_ncs_image]: " << 160 | "exception caught in movidius_ncs_node" << std::endl; 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/param.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #include "movidius_ncs_lib/param.hpp" 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | #include "movidius_ncs_lib/device.hpp" 24 | #include "movidius_ncs_lib/log.hpp" 25 | 26 | namespace movidius_ncs_lib 27 | { 28 | template 29 | void operator>>(const YAML::Node & node, T & i) 30 | { 31 | i = node.as(); 32 | } 33 | 34 | Param::Param() 35 | : device_index_(0), 36 | log_level_(Device::Errors), cnn_type_(""), 37 | graph_file_path_(""), 38 | category_file_path_(""), 39 | network_dimension_(0), 40 | channel1_mean_(0), 41 | channel2_mean_(0), 42 | channel3_mean_(0), 43 | scale_(1.0), 44 | top_n_(1) 45 | { 46 | } 47 | 48 | bool Param::loadParamFromYAML(const std::string & file_path) 49 | { 50 | std::ifstream fin(file_path); 51 | if (fin.fail()) { 52 | ROS_ERROR_STREAM("Could not open " << file_path); 53 | return false; 54 | } 55 | 56 | YAML::Node doc = YAML::Load(fin); 57 | 58 | try { 59 | doc["device_index"] >> device_index_; 60 | } catch (YAML::InvalidScalar) { 61 | ROS_ERROR("The YAML file does not contain a device_index tag or it is invalid."); 62 | return false; 63 | } 64 | 65 | try { 66 | doc["log_level"] >> log_level_; 67 | } catch (YAML::InvalidScalar) { 68 | ROS_ERROR("The YAML file does not contain a log_level tag or it is invalid."); 69 | return false; 70 | } 71 | 72 | try { 73 | doc["top_n"] >> top_n_; 74 | } catch (YAML::InvalidScalar) { 75 | ROS_ERROR("The YAML file does not contain a top_n tag or it is invalid."); 76 | return false; 77 | } 78 | 79 | try { 80 | doc["cnn_type"] >> cnn_type_; 81 | } catch (YAML::InvalidScalar) { 82 | ROS_ERROR("The YAML file does not contain a cnn_type tag or it is invalid."); 83 | return false; 84 | } 85 | 86 | try { 87 | doc["graph_file_path"] >> graph_file_path_; 88 | } catch (YAML::InvalidScalar) { 89 | ROS_ERROR("The YAML file does not contain a device_index tag or it is invalid."); 90 | return false; 91 | } 92 | 93 | try { 94 | doc["category_file_path"] >> category_file_path_; 95 | } catch (YAML::InvalidScalar) { 96 | ROS_ERROR("The YAML file does not contain a category_file_path tag or it is invalid."); 97 | return false; 98 | } 99 | 100 | try { 101 | doc["network_dimension"] >> network_dimension_; 102 | } catch (YAML::InvalidScalar) { 103 | ROS_ERROR("The YAML file does not contain a device_index tag or it is invalid."); 104 | return false; 105 | } 106 | 107 | try { 108 | doc["channel1_mean"] >> channel1_mean_; 109 | } catch (YAML::InvalidScalar) { 110 | ROS_ERROR("The YAML file does not contain a channel1_mean tag or it is invalid."); 111 | return false; 112 | } 113 | 114 | try { 115 | doc["channel2_mean"] >> channel2_mean_; 116 | } catch (YAML::InvalidScalar) { 117 | ROS_ERROR("The YAML file does not contain a channel2_mean tag or it is invalid."); 118 | return false; 119 | } 120 | 121 | try { 122 | doc["channel3_mean"] >> channel3_mean_; 123 | } catch (YAML::InvalidScalar) { 124 | ROS_ERROR("The YAML file does not contain a channel3_mean tag or it is invalid."); 125 | return false; 126 | } 127 | 128 | try { 129 | doc["scale"] >> scale_; 130 | } catch (YAML::InvalidScalar) { 131 | ROS_ERROR("The YAML file does not contain a scale tag or it is invalid."); 132 | return false; 133 | } 134 | return true; 135 | } 136 | 137 | bool Param::validateParam() 138 | { 139 | ROS_DEBUG("NCSImpl get parameters"); 140 | 141 | if (device_index_ < 0) { 142 | ROS_ERROR_STREAM("invalid param device_index = " << device_index_); 143 | throw std::exception(); 144 | return false; 145 | } 146 | 147 | ROS_INFO_STREAM("use device_index = " << device_index_); 148 | 149 | if (log_level_ < Device::Nothing || log_level_ > Device::Verbose) { 150 | ROS_WARN_STREAM("invalid param log_level = " << log_level_); 151 | throw std::exception(); 152 | return false; 153 | } 154 | 155 | ROS_INFO_STREAM("use log_level = " << log_level_); 156 | 157 | if (!std::fstream(graph_file_path_)) { 158 | ROS_ERROR_STREAM("graph_file_path = " << graph_file_path_ << " not exists"); 159 | throw std::exception(); 160 | return false; 161 | } 162 | 163 | ROS_INFO_STREAM("use graph_file_path = " << graph_file_path_); 164 | 165 | if (!std::fstream(category_file_path_)) { 166 | ROS_ERROR_STREAM("category_file_path = " << category_file_path_ << " not exists"); 167 | throw std::exception(); 168 | return false; 169 | } 170 | 171 | ROS_INFO_STREAM("use category_file_path = " << category_file_path_); 172 | 173 | if (cnn_type_.compare("alexnet") && cnn_type_.compare("googlenet") && 174 | cnn_type_.compare("inception_v1") && cnn_type_.compare("inception_v2") && 175 | cnn_type_.compare("inception_v3") && cnn_type_.compare("inception_v4") && 176 | cnn_type_.compare("mobilenet") && cnn_type_.compare("squeezenet") && 177 | cnn_type_.compare("tinyyolo_v1") && cnn_type_.compare("mobilenetssd")) 178 | { 179 | ROS_WARN_STREAM("invalid cnn_type_=" << cnn_type_); 180 | throw std::exception(); 181 | return false; 182 | } 183 | 184 | ROS_INFO_STREAM("use cnn_type_ = " << cnn_type_); 185 | 186 | if (network_dimension_ < 0) { 187 | ROS_WARN_STREAM("invalid network_dimension = " << network_dimension_); 188 | throw std::exception(); 189 | return false; 190 | } 191 | 192 | ROS_INFO_STREAM("use network_dimension = " << network_dimension_); 193 | 194 | ROS_INFO_STREAM("use channel1_mean = " << channel1_mean_); 195 | ROS_INFO_STREAM("use channel2_mean = " << channel2_mean_); 196 | ROS_INFO_STREAM("use channel3_mean = " << channel3_mean_); 197 | 198 | if (top_n_ < 1) { 199 | ROS_WARN_STREAM("invalid top_n = " << top_n_); 200 | throw std::exception(); 201 | return false; 202 | } 203 | 204 | ROS_INFO_STREAM("use top_n = " << top_n_); 205 | 206 | if (scale_ < 0) { 207 | ROS_WARN_STREAM("invalid param scale = " << scale_); 208 | throw std::exception(); 209 | return false; 210 | } 211 | 212 | ROS_INFO_STREAM("use scale = " << scale_); 213 | return true; 214 | } 215 | } // namespace movidius_ncs_lib 216 | -------------------------------------------------------------------------------- /doc/image_classification.md: -------------------------------------------------------------------------------- 1 | ## Classification for Image 2 | This project supports multiple CNN models for classification. Please make sure you have already [set up environment](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#3-environment-setup) and [installed this project](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#4-building-and-installation) correctly. You can refer to the following links for your interested models then. 3 | #### [1 CNN Models](#1-cnn-models-1) 4 | * [AlexNet](#alexnet) 5 | * [GoogleNet](#googlenet) 6 | * [SqueezeNet](#squeezenet) 7 | * [Inception_V1](#inception_v1) 8 | * [Inception_V2](#inception_v2) 9 | * [Inception_V3](#inception_v3) 10 | * [Inception_V4](#inception_v4) 11 | * [MobileNet](#mobilenet) 12 | #### [2 Other Arguments](#2-other-arguments-1) 13 | ---------------------------------- 14 | 15 | ### 1 CNN Models 16 | * #### AlexNet 17 | Compile NCS graph. 18 | ```Shell 19 | cd /opt/movidius/ncappzoo/caffe/AlexNet 20 | make 21 | ``` 22 | Launch object classification service. 23 | ```Shell 24 | cd ~/ros2_ws 25 | echo "param_file: alexnet.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 26 | ament build 27 | source install/local_setup.bash 28 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 29 | ``` 30 | Run the example application with an absolute path of an image on another console. For example, 31 | ```Shell 32 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 33 | ``` 34 | * #### GoogleNet 35 | Compile NCS graph. 36 | ```Shell 37 | cd /opt/movidius/ncappzoo/caffe/GoogleNet 38 | make 39 | ``` 40 | Launch object classification service. 41 | ```Shell 42 | cd ~/ros2_ws 43 | echo "param_file: googlenet.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 44 | ament build 45 | source install/local_setup.bash 46 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 47 | ``` 48 | Run the example application with an absolute path of an image on another console. For example, 49 | ```Shell 50 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 51 | ``` 52 | * #### SqueezeNet 53 | Compile NCS graph. 54 | ```Shell 55 | cd /opt/movidius/ncappzoo/caffe/SqueezeNet 56 | make 57 | ``` 58 | Launch object classification service. 59 | ```Shell 60 | cd ~/ros2_ws 61 | echo "param_file: squeezenet.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 62 | ament build 63 | source install/local_setup.bash 64 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 65 | ``` 66 | Run the example application with an absolute path of an image on another console. For example, 67 | ```Shell 68 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 69 | ``` 70 | * #### Inception_V1 71 | Compile NCS graph. 72 | ```Shell 73 | cd /opt/movidius/ncappzoo/tensorflow/inception_v1 74 | make 75 | ``` 76 | Launch object classification service. 77 | ```Shell 78 | cd ~/ros2_ws 79 | echo "param_file: inception_v1.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 80 | ament build 81 | source install/local_setup.bash 82 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 83 | ``` 84 | Run the example application with an absolute path of an image on another console. For example, 85 | ```Shell 86 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 87 | ``` 88 | * #### Inception_V2 89 | Compile NCS graph. 90 | ```Shell 91 | cd /opt/movidius/ncappzoo/tensorflow/inception_v2 92 | make 93 | ``` 94 | Launch object classification service. 95 | ```Shell 96 | cd ~/ros2_ws 97 | echo "param_file: inception_v2.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 98 | ament build 99 | source install/local_setup.bash 100 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 101 | ``` 102 | Run the example application with an absolute path of an image on another console. For example, 103 | ```Shell 104 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 105 | ``` 106 | * #### Inception_V3 107 | Compile NCS graph. 108 | ```Shell 109 | cd /opt/movidius/ncappzoo/tensorflow/inception_v3 110 | make 111 | ``` 112 | Launch object classification service. 113 | ```Shell 114 | cd ~/ros2_ws 115 | echo "param_file: inception_v3.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 116 | ament build 117 | source install/local_setup.bash 118 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 119 | ``` 120 | Run the example application with an absolute path of an image on another console. For example, 121 | ```Shell 122 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 123 | ``` 124 | * #### Inception_V4 125 | Compile NCS graph. 126 | ```Shell 127 | cd /opt/movidius/ncappzoo/tensorflow/inception_v4 128 | make 129 | ``` 130 | Launch object classification service. 131 | ```Shell 132 | cd ~/ros2_ws 133 | echo "param_file: inception_v4.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 134 | ament build 135 | source install/local_setup.bash 136 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 137 | ``` 138 | Run the example application with an absolute path of an image on another console. For example, 139 | ```Shell 140 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 141 | ``` 142 | * #### MobileNet 143 | Compile NCS graph. 144 | ```Shell 145 | cd /opt/movidius/ncappzoo/tensorflow/mobilenets 146 | make 147 | ``` 148 | Launch object classification service. 149 | ```Shell 150 | cd ~/ros2_ws 151 | echo "param_file: mobilenet.yaml" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 152 | ament build 153 | source install/local_setup.bash 154 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_image_launch.py 155 | ``` 156 | Run the example application with an absolute path of an image on another console. For example, 157 | ```Shell 158 | ros2 run movidius_ncs_example movidius_ncs_example_image_classification /opt/movidius/ncappzoo/data/images/cat.jpg 159 | ``` 160 | ### 2 Other Arguments 161 | |Arguments|Description|Default Value|Valid Values| 162 | |:-|:-|:-|:-| 163 | |device_index|ncs device index|0|0~N-1(N is the maximum number of inserted NCS devices)| 164 | |log_level|ncs log level|0|0:Nothing / 1:Errors / 2:Verbose| 165 | |cnn_type|indicate different cnn models|googlenet|alexnet / googlenet / squeezenet / inception_v1 / inception_v2 / inception_v3 / inception_v4 / mobilenet| 166 | |top_n|the number of results to be shown, only valid for classification|3|0~5| 167 | -------------------------------------------------------------------------------- /movidius_ncs_stream/src/ncs_composition.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "movidius_ncs_stream/ncs_composition.hpp" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "movidius_ncs_lib/exception.hpp" 34 | #include "movidius_ncs_lib/exception_util.hpp" 35 | 36 | 37 | using movidius_ncs_lib::ClassificationResultPtr; 38 | using movidius_ncs_lib::DetectionResultPtr; 39 | using movidius_ncs_lib::Device; 40 | 41 | namespace movidius_ncs_stream 42 | { 43 | template 44 | void operator>>(const YAML::Node & node, T & i) 45 | { 46 | i = node.as(); 47 | } 48 | 49 | NCSComposition::NCSComposition() 50 | : Node("movidius_ncs_stream"), ncs_handle_(nullptr), param_(nullptr) 51 | { 52 | try { 53 | std::string content; 54 | std::string prefix_path; 55 | std::string line; 56 | std::string param_file; 57 | ament_index_cpp::get_resource("packages", "movidius_ncs_launch", content, &prefix_path); 58 | 59 | std::ifstream fin(prefix_path + "/share/movidius_ncs_launch/config/default.yaml"); 60 | if (fin.fail()) { 61 | RCLCPP_ERROR(this->get_logger(), "Could not open default.yaml"); 62 | rclcpp::shutdown(); 63 | } 64 | 65 | YAML::Node doc = YAML::Load(fin); 66 | 67 | doc["param_file"] >> param_file; 68 | doc["input_topic"] >> input_topic_; 69 | 70 | if (param_file.empty() || input_topic_.empty()) { 71 | RCLCPP_ERROR(this->get_logger(), "param_file or input_topic not set, please check " 72 | "default.yaml"); 73 | rclcpp::shutdown(); 74 | } else { 75 | param_ = std::make_shared(); 76 | param_file.erase(param_file.begin(), 77 | std::find_if(param_file.begin(), param_file.end(), 78 | std::not1(std::ptr_fun(std::isspace)))); 79 | if (param_->loadParamFromYAML(prefix_path + "/share/movidius_ncs_launch/config/" + 80 | param_file) && param_->validateParam()) 81 | { 82 | init(); 83 | } else { 84 | rclcpp::shutdown(); 85 | } 86 | } 87 | } catch (YAML::InvalidScalar) { 88 | RCLCPP_ERROR(this->get_logger(), 89 | "The YAML file does not contain param_file & input_topic or it is " "invalid."); 90 | rclcpp::shutdown(); 91 | } catch (movidius_ncs_lib::MvncException & e) { 92 | RCLCPP_ERROR(this->get_logger(), "Error: %s", e.what()); 93 | rclcpp::shutdown(); 94 | } catch (...) { 95 | RCLCPP_ERROR(this->get_logger(), "exception caught while starting NCSNodelet"); 96 | rclcpp::shutdown(); 97 | } 98 | } 99 | 100 | NCSComposition::~NCSComposition() 101 | { 102 | } 103 | 104 | void NCSComposition::init() 105 | { 106 | RCLCPP_DEBUG(this->get_logger(), "NCSNodelet onInit"); 107 | std::vector mean = {param_->channel1_mean_, param_->channel2_mean_, 108 | param_->channel3_mean_}; 109 | ncs_handle_ = std::make_shared( 110 | param_->device_index_, static_cast(param_->log_level_), param_->cnn_type_, 111 | param_->graph_file_path_, param_->category_file_path_, param_->network_dimension_, mean, 112 | param_->scale_, param_->top_n_); 113 | 114 | if (!param_->cnn_type_.compare("alexnet") || !param_->cnn_type_.compare("googlenet") || 115 | !param_->cnn_type_.compare("inception_v1") || !param_->cnn_type_.compare("inception_v2") || 116 | !param_->cnn_type_.compare("inception_v3") || !param_->cnn_type_.compare("inception_v4") || 117 | !param_->cnn_type_.compare("mobilenet") || !param_->cnn_type_.compare("squeezenet")) 118 | { 119 | sub_ = create_subscription( 120 | input_topic_, 121 | std::bind(&NCSComposition::cbClassify, this, std::placeholders::_1), 122 | rmw_qos_profile_sensor_data); 123 | 124 | rmw_qos_profile_t qos = rmw_qos_profile_default; 125 | // qos.depth = 10; 126 | // qos.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; 127 | // qos.history = RMW_QOS_POLICY_HISTORY_KEEP_ALL; 128 | pub_classified_objects_ = create_publisher( 129 | "/movidius_ncs_stream/classified_objects", qos); 130 | } else { 131 | sub_ = create_subscription( 132 | input_topic_, 133 | std::bind(&NCSComposition::cbDetect, this, std::placeholders::_1), 134 | rmw_qos_profile_sensor_data); 135 | 136 | rmw_qos_profile_t qos = rmw_qos_profile_default; 137 | // qos.depth = 10; 138 | // qos.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE; 139 | // qos.history = RMW_QOS_POLICY_HISTORY_KEEP_ALL; 140 | pub_detected_objects_ = create_publisher( 141 | "/movidius_ncs_stream/detected_objects", qos); 142 | } 143 | } 144 | 145 | void NCSComposition::cbClassify(const sensor_msgs::msg::Image::SharedPtr image_msg) 146 | { 147 | cv::Mat cameraData = cv_bridge::toCvCopy(image_msg, "bgr8")->image; 148 | ncs_handle_->loadTensor(cameraData); 149 | ncs_handle_->classify(); 150 | ClassificationResultPtr result = ncs_handle_->getClassificationResult(); 151 | auto objs = std::make_shared(); 152 | 153 | for (auto item : result->items) { 154 | object_msgs::msg::Object obj; 155 | obj.object_name = item.category; 156 | obj.probability = item.probability; 157 | objs->objects_vector.push_back(obj); 158 | } 159 | 160 | objs->header = image_msg->header; 161 | objs->inference_time_ms = result->time_taken; 162 | pub_classified_objects_->publish(objs); 163 | } 164 | 165 | void NCSComposition::cbDetect(const sensor_msgs::msg::Image::SharedPtr image_msg) 166 | { 167 | cv::Mat cameraData = cv_bridge::toCvCopy(image_msg, "bgr8")->image; 168 | ncs_handle_->loadTensor(cameraData); 169 | ncs_handle_->detect(); 170 | DetectionResultPtr result = ncs_handle_->getDetectionResult(); 171 | auto objs_in_boxes = std::make_shared(); 172 | 173 | for (auto item : result->items_in_boxes) { 174 | object_msgs::msg::ObjectInBox obj; 175 | obj.object.object_name = item.item.category; 176 | obj.object.probability = item.item.probability; 177 | obj.roi.x_offset = item.bbox.x; 178 | obj.roi.y_offset = item.bbox.y; 179 | obj.roi.width = item.bbox.width; 180 | obj.roi.height = item.bbox.height; 181 | objs_in_boxes->objects_vector.push_back(obj); 182 | } 183 | 184 | objs_in_boxes->header = image_msg->header; 185 | objs_in_boxes->inference_time_ms = result->time_taken; 186 | pub_detected_objects_->publish(objs_in_boxes); 187 | } 188 | } // namespace movidius_ncs_stream 189 | 190 | CLASS_LOADER_REGISTER_CLASS(movidius_ncs_stream::NCSComposition, rclcpp::Node); 191 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/ncs.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | 16 | #include "movidius_ncs_lib/ncs.hpp" 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "movidius_ncs_lib/exception.hpp" 31 | #include "movidius_ncs_lib/exception_util.hpp" 32 | #include "movidius_ncs_lib/log.hpp" 33 | #include "movidius_ncs_lib/tensor.hpp" 34 | 35 | namespace movidius_ncs_lib 36 | { 37 | NCS::NCS( 38 | int device_index, Device::LogLevel log_level, const std::string & cnn_type, 39 | const std::string & graph_file_path, const std::string & category_file_path, 40 | const int network_dimension, const std::vector & mean, const float & scale, 41 | const int & top_n) 42 | : device_(nullptr), 43 | graph_(nullptr), 44 | tensor_(nullptr), 45 | device_index_(device_index), 46 | log_level_(log_level), 47 | cnn_type_(cnn_type), 48 | network_dimension_(network_dimension), 49 | mean_(mean), 50 | scale_(scale), 51 | top_n_(top_n), 52 | user_param_(nullptr) 53 | { 54 | initDevice(); 55 | loadGraph(graph_file_path); 56 | loadCategories(category_file_path); 57 | tensor_ = std::make_shared(std::pair(network_dimension_, network_dimension_), 58 | mean_, scale_); 59 | result_ = std::make_shared(cnn_type_); 60 | } 61 | 62 | NCS::~NCS() 63 | { 64 | } 65 | 66 | void NCS::classify() 67 | { 68 | assert(graph_->getHandle() != nullptr); 69 | try { 70 | uint16_t * probabilities; 71 | unsigned int length; 72 | int ret = mvncGetResult(graph_->getHandle(), reinterpret_cast(&probabilities), &length, 73 | &user_param_); 74 | ExceptionUtil::tryToThrowMvncException(ret); 75 | std::vector result_vector(reinterpret_cast(probabilities), 76 | reinterpret_cast(probabilities) + length); 77 | ItemsPtr items = std::make_shared(); 78 | for (size_t index = 0; index < length / 2; ++index) { 79 | float fp32; 80 | #ifdef SUPPORT_F16C 81 | fp32 = _cvtsh_ss(probabilities[index]); 82 | #else 83 | Tensor::fp16tofp32(&fp32, probabilities[index]); 84 | #endif 85 | Item item; 86 | item.category = categories_[index]; 87 | item.probability = fp32; 88 | items->push_back(item); 89 | } 90 | 91 | auto cmp = [](const Item & a, const Item & b) {return a.probability > b.probability;}; 92 | std::sort(items->begin(), items->end(), cmp); 93 | 94 | if (!result_->getClassificationResult()->items.empty()) { 95 | result_->getClassificationResult()->items.clear(); 96 | } 97 | 98 | for (auto i : *items) { 99 | result_->setClassificationResult(i); 100 | if (static_cast(result_->getClassificationResult()->items.size()) == top_n_) { 101 | break; 102 | } 103 | } 104 | result_->setClassificationResult(graph_->getTimeTaken()); 105 | device_->monitorThermal(); 106 | } catch (MvncMyriadError & e) { 107 | ROS_ERROR_STREAM(e.what()); 108 | std::string debug_info = graph_->getDebugInfo(); 109 | ROS_ERROR_STREAM("myriad debug info: " << debug_info); 110 | } catch (NCSException & e) { 111 | ROS_ERROR_STREAM(e.what()); 112 | } 113 | } 114 | 115 | void NCS::detect() 116 | { 117 | assert(graph_->getHandle() != nullptr); 118 | try { 119 | uint16_t * result; 120 | unsigned int length; 121 | int ret = mvncGetResult(graph_->getHandle(), reinterpret_cast(&result), &length, 122 | &user_param_); 123 | ExceptionUtil::tryToThrowMvncException(ret); 124 | 125 | std::vector result16_vector(reinterpret_cast(result), 126 | reinterpret_cast(result) + length / 2); 127 | std::vector result32_vector; 128 | 129 | for (auto fp16 : result16_vector) { 130 | float fp32; 131 | #ifdef SUPPORT_F16C 132 | fp32 = _cvtsh_ss(fp16); 133 | #else 134 | Tensor::fp16tofp32(&fp32, fp16); 135 | #endif 136 | result32_vector.push_back(fp32); 137 | } 138 | 139 | if (!cnn_type_.compare("tinyyolo_v1")) { 140 | result_->parseYoloResult(result32_vector, categories_, tensor_->getImageWidth(), 141 | tensor_->getImageHeight()); 142 | result_->setDetectionResult(graph_->getTimeTaken()); 143 | } else if (!cnn_type_.compare("mobilenetssd")) { 144 | result_->parseSSDResult(result32_vector, categories_, tensor_->getImageWidth(), 145 | tensor_->getImageHeight()); 146 | result_->setDetectionResult(graph_->getTimeTaken()); 147 | } else { 148 | ROS_ERROR("unsupported cnn model"); 149 | } 150 | device_->monitorThermal(); 151 | } catch (MvncMyriadError & e) { 152 | ROS_ERROR_STREAM(e.what()); 153 | std::string debug_info = graph_->getDebugInfo(); 154 | ROS_ERROR_STREAM("myriad debug info: " << debug_info); 155 | } catch (std::exception & e) { 156 | ROS_ERROR_STREAM(e.what()); 157 | } 158 | } 159 | 160 | void NCS::loadTensor(const cv::Mat & image) 161 | { 162 | tensor_->clearTensor(); 163 | tensor_->loadImageData(image); 164 | 165 | assert(graph_->getHandle() != nullptr); 166 | int ret = mvncLoadTensor(graph_->getHandle(), tensor_->raw(), tensor_->size(), user_param_); 167 | ExceptionUtil::tryToThrowMvncException(ret); 168 | } 169 | 170 | ClassificationResultPtr NCS::getClassificationResult() 171 | { 172 | return result_->getClassificationResult(); 173 | } 174 | 175 | DetectionResultPtr NCS::getDetectionResult() 176 | { 177 | return result_->getDetectionResult(); 178 | } 179 | 180 | void NCS::initDevice() 181 | { 182 | device_.reset(new Device(device_index_, static_cast(log_level_))); 183 | } 184 | 185 | void NCS::loadGraph(const std::string & graph_file_path) 186 | { 187 | std::string graph = getFileContent(graph_file_path); 188 | graph_.reset(new Graph(device_, graph, network_dimension_)); 189 | } 190 | 191 | void NCS::loadCategories(const std::string & category_file_path) 192 | { 193 | try { 194 | std::string content = getFileContent(category_file_path); 195 | splitIntoLines(content, categories_); 196 | std::string first = categories_[0]; 197 | boost::trim_right(first); 198 | 199 | if (boost::iequals(first, "classes")) { 200 | categories_.erase(categories_.begin()); 201 | } 202 | } catch (int & e) { 203 | throw NCSLoadCategoriesError(); 204 | } 205 | } 206 | 207 | void NCS::splitIntoLines(const std::string & content, std::vector & lines) 208 | { 209 | std::stringstream ss(content); 210 | std::string line; 211 | 212 | while (std::getline(ss, line, '\n')) { 213 | lines.push_back(line); 214 | } 215 | } 216 | 217 | std::string NCS::getFileContent(const std::string & filename) 218 | { 219 | std::ifstream in(filename.c_str(), std::ios::in | std::ios::binary); 220 | 221 | if (!in) { 222 | throw(errno); 223 | } 224 | 225 | std::string content; 226 | in.seekg(0, std::ios::end); 227 | content.reserve(in.tellg()); 228 | in.seekg(0, std::ios::beg); 229 | content.assign(std::istreambuf_iterator(in), std::istreambuf_iterator()); 230 | in.close(); 231 | return content; 232 | } 233 | } // namespace movidius_ncs_lib 234 | -------------------------------------------------------------------------------- /movidius_ncs_lib/src/result.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017 Intel Corporation. All Rights Reserved 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "movidius_ncs_lib/result.hpp" 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace movidius_ncs_lib 27 | { 28 | Result::Result(const std::string & cnn_type) 29 | : classification_result(nullptr), detection_result(nullptr) 30 | { 31 | if (!cnn_type.compare("tinyyolo_v1") || !cnn_type.compare("mobilenetssd")) { 32 | detection_result = std::make_shared(); 33 | } else { 34 | classification_result = std::make_shared(); 35 | } 36 | } 37 | 38 | ClassificationResultPtr Result::getClassificationResult() 39 | { 40 | return classification_result; 41 | } 42 | 43 | DetectionResultPtr Result::getDetectionResult() 44 | { 45 | return detection_result; 46 | } 47 | 48 | void Result::parseYoloResult( 49 | const std::vector & result, 50 | const std::vector categories, int img_width, 51 | int img_height) 52 | { 53 | constexpr int grid_width = 7; 54 | constexpr int grid_height = 7; 55 | constexpr int bbox_num = 2; 56 | constexpr float prob_threshold = 0.2; 57 | constexpr int bbox_conf_num = grid_width * grid_height * bbox_num; 58 | int class_num = categories.size(); 59 | int prob_num = grid_width * grid_height * class_num; 60 | ItemInBBoxArrayPtr objs_in_bboxes = std::make_shared(); 61 | 62 | for (int i = 0; i < grid_height; i++) { 63 | for (int j = 0; j < grid_width; j++) { 64 | for (int k = 0; k < bbox_num; k++) { 65 | int index = i * grid_width * bbox_num + j * bbox_num + k; 66 | ItemInBBox obj_in_bbox; 67 | 68 | std::vector probs(result.begin() + index / 2 * class_num, 69 | result.begin() + index / 2 * class_num + class_num); 70 | float scale = result[prob_num + index]; 71 | std::vector::iterator max_iter = 72 | std::max_element(std::begin(probs), std::end(probs)); 73 | obj_in_bbox.item.probability = *max_iter * scale; 74 | 75 | if (obj_in_bbox.item.probability > prob_threshold) { 76 | obj_in_bbox.item.category = categories[std::distance(std::begin(probs), max_iter)]; 77 | int x_center = 78 | ((result[prob_num + bbox_conf_num + index * 4] + j) / 7.0) * img_width; 79 | int y_center = 80 | ((result[prob_num + bbox_conf_num + index * 4 + 1] + i) / 7.0) * img_height; 81 | obj_in_bbox.bbox.width = (result[prob_num + bbox_conf_num + index * 4 + 2]) * 82 | (result[prob_num + bbox_conf_num + index * 4 + 2]) * img_width; 83 | obj_in_bbox.bbox.height = (result[prob_num + bbox_conf_num + index * 4 + 3]) * 84 | (result[prob_num + bbox_conf_num + index * 4 + 3]) * img_height; 85 | obj_in_bbox.bbox.x = (x_center - 0.5 * obj_in_bbox.bbox.width) < 0 ? 86 | 0 : (x_center - 0.5 * obj_in_bbox.bbox.width); 87 | obj_in_bbox.bbox.y = (y_center - 0.5 * obj_in_bbox.bbox.height) < 0 ? 88 | 0 : (y_center - 0.5 * obj_in_bbox.bbox.height); 89 | objs_in_bboxes->push_back(obj_in_bbox); 90 | } 91 | } 92 | } 93 | } 94 | 95 | NMS(objs_in_bboxes); 96 | 97 | if (!detection_result->items_in_boxes.empty()) { 98 | detection_result->items_in_boxes.clear(); 99 | } 100 | 101 | for (auto item : *objs_in_bboxes) { 102 | detection_result->items_in_boxes.push_back(item); 103 | } 104 | } 105 | 106 | void Result::parseSSDResult( 107 | const std::vector & result, 108 | const std::vector categories, int img_width, 109 | int img_height) 110 | { 111 | constexpr int num_in_group = 7; 112 | int num_detection = result.at(0); 113 | ItemInBBoxArrayPtr objs_in_bboxes = std::make_shared(); 114 | 115 | for (int i = 0; i < num_detection; i++) { 116 | int category_id = result[(i + 1) * num_in_group + 1]; 117 | float probability = result[(i + 1) * num_in_group + 2]; 118 | int xmin = result[(i + 1) * num_in_group + 3] * img_width; 119 | int ymin = result[(i + 1) * num_in_group + 4] * img_height; 120 | int xmax = result[(i + 1) * num_in_group + 5] * img_width; 121 | int ymax = result[(i + 1) * num_in_group + 6] * img_height; 122 | 123 | ItemInBBox obj_in_bbox; 124 | if (std::isnan(category_id) || std::isnan(probability) || std::isnan(xmin) || xmin < 0 || 125 | xmin > img_width || std::isnan(ymin) || ymin < 0 || ymin > img_height || std::isnan(xmax) || 126 | xmax < 0 || xmax > img_width || std::isnan(ymax) || ymax < 0 || ymax > img_height) 127 | { 128 | continue; 129 | } else { 130 | obj_in_bbox.item.category = categories.at(category_id); 131 | obj_in_bbox.item.probability = probability; 132 | obj_in_bbox.bbox.width = xmax - xmin; 133 | obj_in_bbox.bbox.height = ymax - ymin; 134 | obj_in_bbox.bbox.x = xmin; 135 | obj_in_bbox.bbox.y = ymin; 136 | objs_in_bboxes->push_back(obj_in_bbox); 137 | } 138 | } 139 | 140 | NMS(objs_in_bboxes); 141 | 142 | if (!detection_result->items_in_boxes.empty()) { 143 | detection_result->items_in_boxes.clear(); 144 | } 145 | 146 | for (auto item : *objs_in_bboxes) { 147 | detection_result->items_in_boxes.push_back(item); 148 | } 149 | } 150 | 151 | void Result::setClassificationResult(Item item) 152 | { 153 | classification_result->items.push_back(item); 154 | } 155 | 156 | void Result::setClassificationResult(float time) 157 | { 158 | classification_result->time_taken = time; 159 | } 160 | 161 | void Result::setDetectionResult(ItemInBBox item) 162 | { 163 | detection_result->items_in_boxes.push_back(item); 164 | } 165 | 166 | void Result::setDetectionResult(float time) 167 | { 168 | detection_result->time_taken = time; 169 | } 170 | 171 | void Result::NMS(ItemInBBoxArrayPtr objs_in_bboxes) 172 | { 173 | constexpr float iou_threshold = 0.5; 174 | 175 | auto cmp = [](const ItemInBBox & a, const ItemInBBox & b) { 176 | return a.item.probability > b.item.probability; 177 | }; 178 | std::sort(objs_in_bboxes->begin(), objs_in_bboxes->end(), cmp); 179 | 180 | for (auto iter1 = objs_in_bboxes->begin(); iter1 != objs_in_bboxes->end(); iter1++) { 181 | if (iter1->item.probability == 0) { 182 | continue; 183 | } 184 | for (auto iter2 = iter1 + 1; iter2 != objs_in_bboxes->end(); iter2++) { 185 | if (IOU(*iter1, *iter2) > iou_threshold) { 186 | iter2->item.probability = 0; 187 | } 188 | } 189 | } 190 | 191 | for (auto iter = objs_in_bboxes->begin(); iter != objs_in_bboxes->end(); ) { 192 | if (iter->item.probability == 0) { 193 | iter = objs_in_bboxes->erase(iter); 194 | } else { 195 | iter++; 196 | } 197 | } 198 | } 199 | 200 | float Result::IOU(ItemInBBox box1, ItemInBBox box2) 201 | { 202 | int xmax = (box1.bbox.x + box1.bbox.width < box2.bbox.x + box2.bbox.width) ? 203 | box1.bbox.x + box1.bbox.width : box2.bbox.x + box2.bbox.width; 204 | int xmin = (box1.bbox.x > box2.bbox.x) ? box1.bbox.x : box2.bbox.x; 205 | int ymax = (box1.bbox.y + box1.bbox.height < box2.bbox.y + box2.bbox.height) ? 206 | box1.bbox.y + box1.bbox.height : box2.bbox.y + box2.bbox.height; 207 | int ymin = (box1.bbox.y > box2.bbox.y) ? box1.bbox.y : box2.bbox.y; 208 | int inter_w = xmax - xmin; 209 | int inter_h = ymax - ymin; 210 | int inter_area = 0; 211 | if (inter_w > 0 && inter_h > 0) { 212 | inter_area = inter_w * inter_h; 213 | } 214 | return inter_area * 1.0 / 215 | (box1.bbox.width * box1.bbox.height + box2.bbox.width * box2.bbox.height - inter_area); 216 | } 217 | } // namespace movidius_ncs_lib 218 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | 11 | Contact: webadmin@linux.intel.com 12 | # ros2_intel_movidius_ncs 13 | # Warning: This repo is deprecated. For latest ROS2 wrapper for Movidius NCS, please refer to our project ros2_openvino_toolkit. 14 | # See: https://github.com/intel/ros2_openvino_toolkit!! 15 | 16 | ## 1 Introduction 17 | The Movidius™ Neural Compute Stick ([NCS](https://developer.movidius.com/)) is a tiny fanless deep learning device that you can use to learn AI programming at the edge. NCS is powered by the same low power high performance Movidius™ Vision Processing Unit ([VPU](https://www.movidius.com/solutions/vision-processing-unit)) that can be found in millions of smart security cameras, gesture controlled drones, industrial machine vision equipment, and more. 18 | 19 | This project is a ROS2 wrapper for NC API of [NCSDK](https://movidius.github.io/ncsdk/), providing the following features: 20 | * A ROS2 service for object classification and detection of a static image file 21 | * A ROS2 publisher for object classification and detection of a video stream from a RGB camera 22 | * Demo applications to show the capabilities of ROS2 service and publisher 23 | * Support multiple CNN models of Caffe and Tensorflow 24 | 25 | ## 2 Prerequisite 26 | * An x86_64 computer running Ubuntu 16.04. OS X and Windows are not supported yet 27 | * ROS2 Bouncy 28 | * Movidius Neural Compute Stick (NCS) 29 | * Movidius Neural Compute (MvNC) SDK 30 | * Movidius Neural Compute Application Zoo 31 | * RGB Camera, e.g. RealSense D400 Series 32 | 33 | ## 3 Environment Setup 34 | * Install OpenCV 3.x ([guide](https://docs.opencv.org/3.3.0/d7/d9f/tutorial_linux_install.html)) 35 | * Install ROS2 Ardent ([guide](https://github.com/ros2/ros2/wiki/Linux-Install-Debians)) 36 | * Create a ROS2 workspace 37 | ```Shell 38 | mkdir -p ~/ros2_ws/src 39 | ``` 40 | * Install NCSDK [v1.12.00](https://github.com/movidius/ncsdk/releases) ([github](https://github.com/movidius/ncsdk)) 41 | * Install NC APP Zoo([github](https://github.com/movidius/ncappzoo)) 42 | * NCSDK should be installed in ```/opt/movidius``` by default. Create a symbol link in ```/opt/movidius``` to NC APP Zoo. 43 | ```Shell 44 | sudo ln -s /ncappzoo /opt/movidius/ncappzoo 45 | ``` 46 | After that, make sure you can find graph data in ```/opt/movidius/ncappzoo/caffe``` or ```/opt/movidius/ncappzoo/tensorflow``` and image data in ```/opt/movidius/ncappzoo/data/images``` 47 | * Install object_msgs for ROS2 ([github](https://github.com/intel/ros2_object_msgs)) 48 | * Install ROS2 package for different cameras as needed. e.g. 49 | 1. RealSense D400 series camera ([github](https://github.com/intel/ros2_intel_realsense)) 50 |   **Note**: Create a symbol link from libusb.a to libusb-1.0.a, otherwise "libusb.a" is probably not to be found by librealsense. 51 |    ```sudo ln -s /usr/lib/x86_64-linux-gnu/libusb-1.0.a /usr/lib/libusb.a``` 52 | * Install ROS2 Message Filters ([github](https://github.com/ros2/message_filters)) 53 | ```Shell 54 | cd /usr/lib/x86_64-linux-gnu 55 | sudo ln -s libboost_python-py35.so libboost_python3.so 56 | cd ~/ros2_ws/src 57 | git clone https://github.com/ros2/message_filters 58 | ``` 59 | * Install ROS2 vision_opencv ([github](https://github.com/ros-perception/vision_opencv)) 60 | ```Shell 61 | cd ~/ros2_ws/src 62 | git clone https://github.com/ros-perception/vision_opencv 63 | cd vision_opencv 64 | git checkout ros2 65 | ``` 66 | 67 | ## 4 Building and Installation 68 | ```Shell 69 | cd ~/ros2_ws/src 70 | git clone https://github.com/intel/ros2_intel_movidius_ncs 71 | git clone https://github.com/intel/ros2_object_msgs 72 | cd ~/ros2_ws 73 | ament build 74 | source install/local_setup.bash 75 | ``` 76 | Copy object label file from this project to NCSDK installation location. 77 | ```Shell 78 | cp ~/ros2_ws/src/ros2_intel_movidius_ncs/data/labels/* /opt/movidius/ncappzoo/data/ilsvrc12/ 79 | ``` 80 | 81 | ## 5 Running the Demo 82 | ### 5.1 Classification 83 | #### 5.1.1 Supported CNN Models 84 | ###### *Table1* 85 | |CNN Model|Framework|Usage| 86 | |:-|:-|:-| 87 | |AlexNet|Caffe|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#alexnet)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#alexnet)| 88 | |GoogLeNet|Caffe|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#googlenet)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#googlenet)| 89 | |SqueezeNet|Caffe|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#squeezenet)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#squeezenet)| 90 | |Inception_v1|Tensorflow|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#inception_v1)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#inception_v1)| 91 | |Inception_v2|Tensorflow|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#inception_v2)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#inception_v2)| 92 | |Inception_v3|Tensorflow|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#inception_v3)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#inception_v3)| 93 | |Inception_v4|Tensorflow|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#inception_v4)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#inception_v4)| 94 | |MobileNet|Tensorflow|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md#mobilenet)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md#mobilenet)| 95 | #### 5.1.2 Classification Result with GoogLeNet 96 | ![classification with googlenet](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/data/results/googlenet_dog.png "classification with googlenet") 97 | #### 5.1.3 Running the Demo 98 | * [Static Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_classification.md) 99 | * [Video Streaming](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_classification.md) 100 | 101 | ### 5.2 Detection 102 | #### 5.1.1 Supported CNN Models 103 | |CNN Model|Framework|Usage| 104 | |:-|:-|:-| 105 | |MobileNetSSD(Recommended)|Caffe|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_detection.md#mobilenet_ssd)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_detection.md#mobilenet_ssd)| 106 | |TinyYolo_v1|Caffe|[Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_detection.md#tinyyolo_v1)/[Video](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_detection.md#tinyyolo_v1)| 107 | #### 5.1.2 Detection Result with MobileNetSSD 108 | ![detection with mobilenetssd](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/data/results/mobilenetssd_car_bicycle.png "detection with mobilenetssd") 109 | #### 5.1.3 Running the Demo 110 | * [Static Image](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/image_detection.md) 111 | * [Video Streaming](https://github.com/intel/ros2_intel_movidius_ncs/blob/master/doc/video_detection.md) 112 | 113 | ## 6 Interfaces 114 | ### 6.1 Topic 115 | Classification: ```/movidius_ncs_nodelet/classified_objects``` 116 | Detection: ```/movidius_ncs_nodelet/detected_objects``` 117 | ### 6.2 Service 118 | Classification: ```/movidius_ncs_image/classify_object``` 119 | Detection: ```/movidius_ncs_image/detect_object``` 120 | 121 | ## 7 Known Issues 122 | * Only absolute path of image file supported in image inference demo 123 | * Only test on RealSense D400 series camera 124 | 125 | ## 8 TODO 126 | * Keep synchronized with [ROS NCS Package](https://github.com/intel/ros_intel_movidius_ncs/tree/master) 127 | 128 | 129 | ###### *Any security issue should be reported using process at https://01.org/security* 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2017 Intel Corporation 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /doc/video_classification.md: -------------------------------------------------------------------------------- 1 | ## Classification for Video 2 | This project supports multiple CNN models for classification. Please make sure you have already [set up environment](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#3-environment-setup) and [installed this project](https://github.com/intel/ros2_intel_movidius_ncs/tree/master#4-building-and-installation) correctly. You can refer to the following links for your interested models then. 3 | #### [1 CNN Models](#1-cnn-models-1) 4 | * [AlexNet](#alexnet) 5 | * [GoogLeNet](#googlenet) 6 | * [SqueezeNet](#squeezenet) 7 | * [Inception_V1](#inception_v1) 8 | * [Inception_V2](#inception_v2) 9 | * [Inception_V3](#inception_v3) 10 | * [Inception_V4](#inception_v4) 11 | * [MobileNet](#mobilenet) 12 | #### [2 Run with Other ROS Supported Cameras](#2-run-with-other-ros-supported-cameras-1) 13 | #### [3 Other Arguments](#3-other-arguments-1) 14 | ---------------------------------- 15 | 16 | ### 1 CNN Models 17 | * #### AlexNet 18 | Compile NCS graph. 19 | ```Shell 20 | cd /opt/movidius/ncappzoo/caffe/AlexNet 21 | make 22 | ``` 23 | Launch video streaming nodelet. 24 | - Option 1: RealSense 25 | ```Shell 26 | # Choose CNN model 27 | cd ~/ros2_ws 28 | echo -e "param_file: alexnet.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 29 | ament build 30 | source install/local_setup.bash 31 | # Terminal 1, run realsense camera 32 | realsense_ros2_camera 33 | # Terminal 2, run video streaming composition manager 34 | ros2 run composition api_composition 35 | # Terminal 3, launch video streaming composistion 36 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 37 | ``` 38 | - Option 2: Astra 39 | ```Shell 40 | # Choose CNN model 41 | cd ~/ros2_ws 42 | echo -e "param_file: alexnet.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 43 | ament build 44 | source install/local_setup.bash 45 | # Terminal 1, run astra camera 46 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 47 | # Terminal 2, run video streaming composition manager 48 | ros2 run composition api_composition 49 | # Terminal 3, launch video streaming composistion 50 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 51 | ``` 52 | Launch image viewer to show the classification result on another console. 53 | ```Shell 54 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 55 | ``` 56 | * #### GoogLeNet 57 | Compile NCS graph. 58 | ```Shell 59 | cd /opt/movidius/ncappzoo/caffe/GoogLeNet 60 | make 61 | ``` 62 | Launch video streaming nodelet. 63 | - Option 1: RealSense 64 | ```Shell 65 | # Choose CNN model 66 | cd ~/ros2_ws 67 | echo -e "param_file: googlenet.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 68 | ament build 69 | source install/local_setup.bash 70 | # Terminal 1, run realsense camera 71 | realsense_ros2_camera 72 | # Terminal 2, run video streaming composition manager 73 | ros2 run composition api_composition 74 | # Terminal 3, launch video streaming composistion 75 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 76 | ``` 77 | - Option 2: Astra 78 | ```Shell 79 | # Choose CNN model 80 | cd ~/ros2_ws 81 | echo -e "param_file: googlenet.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 82 | ament build 83 | source install/local_setup.bash 84 | # Terminal 1, run astra camera 85 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 86 | # Terminal 2, run video streaming composition manager 87 | ros2 run composition api_composition 88 | # Terminal 3, launch video streaming composistion 89 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 90 | ``` 91 | Launch image viewer to show the classification result on another console. 92 | ```Shell 93 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 94 | ``` 95 | * #### SqueezeNet 96 | Compile NCS graph. 97 | ```Shell 98 | cd /opt/movidius/ncappzoo/caffe/SqueezeNet 99 | make 100 | ``` 101 | Launch video streaming nodelet. 102 | - Option 1: RealSense 103 | ```Shell 104 | # Choose CNN model 105 | cd ~/ros2_ws 106 | echo -e "param_file: squeezenet.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 107 | ament build 108 | source install/local_setup.bash 109 | # Terminal 1, run realsense camera 110 | realsense_ros2_camera 111 | # Terminal 2, run video streaming composition manager 112 | ros2 run composition api_composition 113 | # Terminal 3, launch video streaming composistion 114 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 115 | ``` 116 | - Option 2: Astra 117 | ```Shell 118 | # Choose CNN model 119 | cd ~/ros2_ws 120 | echo -e "param_file: squeezenet.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 121 | ament build 122 | source install/local_setup.bash 123 | # Terminal 1, run astra camera 124 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 125 | # Terminal 2, run video streaming composition manager 126 | ros2 run composition api_composition 127 | # Terminal 3, launch video streaming composistion 128 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 129 | ``` 130 | Launch image viewer to show the classification result on another console. 131 | ```Shell 132 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 133 | ``` 134 | * #### Inception_V1 135 | Compile NCS graph. 136 | ```Shell 137 | cd /opt/movidius/ncappzoo/tensorflow/inception_v1 138 | make 139 | ``` 140 | Launch video streaming nodelet. 141 | - Option 1: RealSense 142 | ```Shell 143 | # Choose CNN model 144 | cd ~/ros2_ws 145 | echo -e "param_file: inception_v1.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 146 | ament build 147 | source install/local_setup.bash 148 | # Terminal 1, run realsense camera 149 | realsense_ros2_camera 150 | # Terminal 2, run video streaming composition manager 151 | ros2 run composition api_composition 152 | # Terminal 3, launch video streaming composistion 153 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 154 | ``` 155 | - Option 2: Astra 156 | ```Shell 157 | # Choose CNN model 158 | cd ~/ros2_ws 159 | echo -e "param_file: inception_v1.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 160 | ament build 161 | source install/local_setup.bash 162 | # Terminal 1, run astra camera 163 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 164 | # Terminal 2, run video streaming composition manager 165 | ros2 run composition api_composition 166 | # Terminal 3, launch video streaming composistion 167 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 168 | ``` 169 | Launch image viewer to show the classification result on another console. 170 | ```Shell 171 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 172 | ``` 173 | * #### Inception_V2 174 | Compile NCS graph. 175 | ```Shell 176 | cd /opt/movidius/ncappzoo/tensorflow/inception_v2 177 | make 178 | ``` 179 | Launch video streaming nodelet. 180 | - Option 1: RealSense 181 | ```Shell 182 | # Choose CNN model 183 | cd ~/ros2_ws 184 | echo -e "param_file: inception_v2.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 185 | ament build 186 | source install/local_setup.bash 187 | # Terminal 1, run realsense camera 188 | realsense_ros2_camera 189 | # Terminal 2, run video streaming composition manager 190 | ros2 run composition api_composition 191 | # Terminal 3, launch video streaming composistion 192 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 193 | ``` 194 | - Option 2: Astra 195 | ```Shell 196 | # Choose CNN model 197 | cd ~/ros2_ws 198 | echo -e "param_file: inception_v2.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 199 | ament build 200 | source install/local_setup.bash 201 | # Terminal 1, run astra camera 202 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 203 | # Terminal 2, run video streaming composition manager 204 | ros2 run composition api_composition 205 | # Terminal 3, launch video streaming composistion 206 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 207 | ``` 208 | Launch image viewer to show the classification result on another console. 209 | ```Shell 210 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 211 | ``` 212 | * #### Inception_V3 213 | Compile NCS graph. 214 | ```Shell 215 | cd /opt/movidius/ncappzoo/tensorflow/inception_v3 216 | make 217 | ``` 218 | Launch video streaming nodelet. 219 | - Option 1: RealSense 220 | ```Shell 221 | # Choose CNN model 222 | cd ~/ros2_ws 223 | echo -e "param_file: inception_v3.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 224 | ament build 225 | source install/local_setup.bash 226 | # Terminal 1, run realsense camera 227 | realsense_ros2_camera 228 | # Terminal 2, run video streaming composition manager 229 | ros2 run composition api_composition 230 | # Terminal 3, launch video streaming composistion 231 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 232 | ``` 233 | - Option 2: Astra 234 | ```Shell 235 | # Choose CNN model 236 | cd ~/ros2_ws 237 | echo -e "param_file: inception_v3.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 238 | ament build 239 | source install/local_setup.bash 240 | # Terminal 1, run astra camera 241 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 242 | # Terminal 2, run video streaming composition manager 243 | ros2 run composition api_composition 244 | # Terminal 3, launch video streaming composistion 245 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 246 | ``` 247 | Launch image viewer to show the classification result on another console. 248 | ```Shell 249 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 250 | ``` 251 | * #### Inception_V4 252 | Compile NCS graph. 253 | ```Shell 254 | cd /opt/movidius/ncappzoo/tensorflow/inception_v4 255 | make 256 | ``` 257 | Launch video streaming nodelet. 258 | - Option 1: RealSense 259 | ```Shell 260 | # Choose CNN model 261 | cd ~/ros2_ws 262 | echo -e "param_file: inception_v4.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 263 | ament build 264 | source install/local_setup.bash 265 | # Terminal 1, run realsense camera 266 | realsense_ros2_camera 267 | # Terminal 2, run video streaming composition manager 268 | ros2 run composition api_composition 269 | # Terminal 3, launch video streaming composistion 270 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 271 | ``` 272 | - Option 2: Astra 273 | ```Shell 274 | # Choose CNN model 275 | cd ~/ros2_ws 276 | echo -e "param_file: inception_v4.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 277 | ament build 278 | source install/local_setup.bash 279 | # Terminal 1, run astra camera 280 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 281 | # Terminal 2, run video streaming composition manager 282 | ros2 run composition api_composition 283 | # Terminal 3, launch video streaming composistion 284 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 285 | ``` 286 | Launch image viewer to show the classification result on another console. 287 | ```Shell 288 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 289 | ``` 290 | * #### MobileNet 291 | Compile NCS graph. 292 | ```Shell 293 | cd /opt/movidius/ncappzoo/tensorflow/mobilenets 294 | make 295 | ``` 296 | Launch video streaming nodelet. 297 | - Option 1: RealSense 298 | ```Shell 299 | # Choose CNN model 300 | cd ~/ros2_ws 301 | echo -e "param_file: mobilenet.yaml\ninput_topic: /camera/color/image_raw" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 302 | ament build 303 | source install/local_setup.bash 304 | # Terminal 1, run realsense camera 305 | realsense_ros2_camera 306 | # Terminal 2, run video streaming composition manager 307 | ros2 run composition api_composition 308 | # Terminal 3, launch video streaming composistion 309 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 310 | ``` 311 | - Option 2: Astra 312 | ```Shell 313 | # Choose CNN model 314 | cd ~/ros2_ws 315 | echo -e "param_file: mobilenet.yaml\ninput_topic: /image" > src/ros2_intel_movidius_ncs/movidius_ncs_launch/config/default.yaml 316 | ament build 317 | source install/local_setup.bash 318 | # Terminal 1, run astra camera 319 | ros2 run astra_camera astra_camera_node -w 640 -h 480 -I -D 320 | # Terminal 2, run video streaming composition manager 321 | ros2 run composition api_composition 322 | # Terminal 3, launch video streaming composistion 323 | launch `ros2 pkg prefix movidius_ncs_launch`/share/movidius_ncs_launch/launch/ncs_stream_launch.py 324 | ``` 325 | Launch image viewer to show the classification result on another console. 326 | ```Shell 327 | ros2 run movidius_ncs_example movidius_ncs_example_stream_classification 328 | ``` 329 | ### 2 Run with Other ROS Supported Cameras 330 | TODO 331 | 332 | ### 3 Other Arguments 333 | |Arguments|Description|Default Value|Valid Values| 334 | |:-|:-|:-|:-| 335 | |device_index|ncs device index|0|0~N-1(N is the maximum number of inserted NCS devices)| 336 | |log_level|ncs log level|0|0:Nothing / 1:Errors / 2:Verbose| 337 | |cnn_type|indicate different cnn models|googlenet|alexnet / googlenet / squeezenet / inception_v1 / inception_v2 / inception_v3 / inception_v4 / mobilenet| 338 | |top_n|the number of results to be shown, only valid for classification|3|0~5| 339 | -------------------------------------------------------------------------------- /data/labels/imagenet1000.txt: -------------------------------------------------------------------------------- 1 | classes 2 | tench, Tinca tinca 3 | goldfish, Carassius auratus 4 | great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias 5 | tiger shark, Galeocerdo cuvieri 6 | hammerhead, hammerhead shark 7 | electric ray, crampfish, numbfish, torpedo 8 | stingray 9 | cock 10 | hen 11 | ostrich, Struthio camelus 12 | brambling, Fringilla montifringilla 13 | goldfinch, Carduelis carduelis 14 | house finch, linnet, Carpodacus mexicanus 15 | junco, snowbird 16 | indigo bunting, indigo finch, indigo bird, Passerina cyanea 17 | robin, American robin, Turdus migratorius 18 | bulbul 19 | jay 20 | magpie 21 | chickadee 22 | water ouzel, dipper 23 | kite 24 | bald eagle, American eagle, Haliaeetus leucocephalus 25 | vulture 26 | great grey owl, great gray owl, Strix nebulosa 27 | European fire salamander, Salamandra salamandra 28 | common newt, Triturus vulgaris 29 | eft 30 | spotted salamander, Ambystoma maculatum 31 | axolotl, mud puppy, Ambystoma mexicanum 32 | bullfrog, Rana catesbeiana 33 | tree frog, tree-frog 34 | tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui 35 | loggerhead, loggerhead turtle, Caretta caretta 36 | leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea 37 | mud turtle 38 | terrapin 39 | box turtle, box tortoise 40 | banded gecko 41 | common iguana, iguana, Iguana iguana 42 | American chameleon, anole, Anolis carolinensis 43 | whiptail, whiptail lizard 44 | agama 45 | frilled lizard, Chlamydosaurus kingi 46 | alligator lizard 47 | Gila monster, Heloderma suspectum 48 | green lizard, Lacerta viridis 49 | African chameleon, Chamaeleo chamaeleon 50 | Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis 51 | African crocodile, Nile crocodile, Crocodylus niloticus 52 | American alligator, Alligator mississipiensis 53 | triceratops 54 | thunder snake, worm snake, Carphophis amoenus 55 | ringneck snake, ring-necked snake, ring snake 56 | hognose snake, puff adder, sand viper 57 | green snake, grass snake 58 | king snake, kingsnake 59 | garter snake, grass snake 60 | water snake 61 | vine snake 62 | night snake, Hypsiglena torquata 63 | boa constrictor, Constrictor constrictor 64 | rock python, rock snake, Python sebae 65 | Indian cobra, Naja naja 66 | green mamba 67 | sea snake 68 | horned viper, cerastes, sand viper, horned asp, Cerastes cornutus 69 | diamondback, diamondback rattlesnake, Crotalus adamanteus 70 | sidewinder, horned rattlesnake, Crotalus cerastes 71 | trilobite 72 | harvestman, daddy longlegs, Phalangium opilio 73 | scorpion 74 | black and gold garden spider, Argiope aurantia 75 | barn spider, Araneus cavaticus 76 | garden spider, Aranea diademata 77 | black widow, Latrodectus mactans 78 | tarantula 79 | wolf spider, hunting spider 80 | tick 81 | centipede 82 | black grouse 83 | ptarmigan 84 | ruffed grouse, partridge, Bonasa umbellus 85 | prairie chicken, prairie grouse, prairie fowl 86 | peacock 87 | quail 88 | partridge 89 | African grey, African gray, Psittacus erithacus 90 | macaw 91 | sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita 92 | lorikeet 93 | coucal 94 | bee eater 95 | hornbill 96 | hummingbird 97 | jacamar 98 | toucan 99 | drake 100 | red-breasted merganser, Mergus serrator 101 | goose 102 | black swan, Cygnus atratus 103 | tusker 104 | echidna, spiny anteater, anteater 105 | platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus 106 | wallaby, brush kangaroo 107 | koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus 108 | wombat 109 | jellyfish 110 | sea anemone, anemone 111 | brain coral 112 | flatworm, platyhelminth 113 | nematode, nematode worm, roundworm 114 | conch 115 | snail 116 | slug 117 | sea slug, nudibranch 118 | chiton, coat-of-mail shell, sea cradle, polyplacophore 119 | chambered nautilus, pearly nautilus, nautilus 120 | Dungeness crab, Cancer magister 121 | rock crab, Cancer irroratus 122 | fiddler crab 123 | king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica 124 | American lobster, Northern lobster, Maine lobster, Homarus americanus 125 | spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish 126 | crayfish, crawfish, crawdad, crawdaddy 127 | hermit crab 128 | isopod 129 | white stork, Ciconia ciconia 130 | black stork, Ciconia nigra 131 | spoonbill 132 | flamingo 133 | little blue heron, Egretta caerulea 134 | American egret, great white heron, Egretta albus 135 | bittern 136 | crane 137 | limpkin, Aramus pictus 138 | European gallinule, Porphyrio porphyrio 139 | American coot, marsh hen, mud hen, water hen, Fulica americana 140 | bustard 141 | ruddy turnstone, Arenaria interpres 142 | red-backed sandpiper, dunlin, Erolia alpina 143 | redshank, Tringa totanus 144 | dowitcher 145 | oystercatcher, oyster catcher 146 | pelican 147 | king penguin, Aptenodytes patagonica 148 | albatross, mollymawk 149 | grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus 150 | killer whale, killer, orca, grampus, sea wolf, Orcinus orca 151 | dugong, Dugong dugon 152 | sea lion 153 | Chihuahua 154 | Japanese spaniel 155 | Maltese dog, Maltese terrier, Maltese 156 | Pekinese, Pekingese, Peke 157 | Shih-Tzu 158 | Blenheim spaniel 159 | papillon 160 | toy terrier 161 | Rhodesian ridgeback 162 | Afghan hound, Afghan 163 | basset, basset hound 164 | beagle 165 | bloodhound, sleuthhound 166 | bluetick 167 | black-and-tan coonhound 168 | Walker hound, Walker foxhound 169 | English foxhound 170 | redbone 171 | borzoi, Russian wolfhound 172 | Irish wolfhound 173 | Italian greyhound 174 | whippet 175 | Ibizan hound, Ibizan Podenco 176 | Norwegian elkhound, elkhound 177 | otterhound, otter hound 178 | Saluki, gazelle hound 179 | Scottish deerhound, deerhound 180 | Weimaraner 181 | Staffordshire bullterrier, Staffordshire bull terrier 182 | American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier 183 | Bedlington terrier 184 | Border terrier 185 | Kerry blue terrier 186 | Irish terrier 187 | Norfolk terrier 188 | Norwich terrier 189 | Yorkshire terrier 190 | wire-haired fox terrier 191 | Lakeland terrier 192 | Sealyham terrier, Sealyham 193 | Airedale, Airedale terrier 194 | cairn, cairn terrier 195 | Australian terrier 196 | Dandie Dinmont, Dandie Dinmont terrier 197 | Boston bull, Boston terrier 198 | miniature schnauzer 199 | giant schnauzer 200 | standard schnauzer 201 | Scotch terrier, Scottish terrier, Scottie 202 | Tibetan terrier, chrysanthemum dog 203 | silky terrier, Sydney silky 204 | soft-coated wheaten terrier 205 | West Highland white terrier 206 | Lhasa, Lhasa apso 207 | flat-coated retriever 208 | curly-coated retriever 209 | golden retriever 210 | Labrador retriever 211 | Chesapeake Bay retriever 212 | German short-haired pointer 213 | vizsla, Hungarian pointer 214 | English setter 215 | Irish setter, red setter 216 | Gordon setter 217 | Brittany spaniel 218 | clumber, clumber spaniel 219 | English springer, English springer spaniel 220 | Welsh springer spaniel 221 | cocker spaniel, English cocker spaniel, cocker 222 | Sussex spaniel 223 | Irish water spaniel 224 | kuvasz 225 | schipperke 226 | groenendael 227 | malinois 228 | briard 229 | kelpie 230 | komondor 231 | Old English sheepdog, bobtail 232 | Shetland sheepdog, Shetland sheep dog, Shetland 233 | collie 234 | Border collie 235 | Bouvier des Flandres, Bouviers des Flandres 236 | Rottweiler 237 | German shepherd, German shepherd dog, German police dog, alsatian 238 | Doberman, Doberman pinscher 239 | miniature pinscher 240 | Greater Swiss Mountain dog 241 | Bernese mountain dog 242 | Appenzeller 243 | EntleBucher 244 | boxer 245 | bull mastiff 246 | Tibetan mastiff 247 | French bulldog 248 | Great Dane 249 | Saint Bernard, St Bernard 250 | Eskimo dog, husky 251 | malamute, malemute, Alaskan malamute 252 | Siberian husky 253 | dalmatian, coach dog, carriage dog 254 | affenpinscher, monkey pinscher, monkey dog 255 | basenji 256 | pug, pug-dog 257 | Leonberg 258 | Newfoundland, Newfoundland dog 259 | Great Pyrenees 260 | Samoyed, Samoyede 261 | Pomeranian 262 | chow, chow chow 263 | keeshond 264 | Brabancon griffon 265 | Pembroke, Pembroke Welsh corgi 266 | Cardigan, Cardigan Welsh corgi 267 | toy poodle 268 | miniature poodle 269 | standard poodle 270 | Mexican hairless 271 | timber wolf, grey wolf, gray wolf, Canis lupus 272 | white wolf, Arctic wolf, Canis lupus tundrarum 273 | red wolf, maned wolf, Canis rufus, Canis niger 274 | coyote, prairie wolf, brush wolf, Canis latrans 275 | dingo, warrigal, warragal, Canis dingo 276 | dhole, Cuon alpinus 277 | African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus 278 | hyena, hyaena 279 | red fox, Vulpes vulpes 280 | kit fox, Vulpes macrotis 281 | Arctic fox, white fox, Alopex lagopus 282 | grey fox, gray fox, Urocyon cinereoargenteus 283 | tabby, tabby cat 284 | tiger cat 285 | Persian cat 286 | Siamese cat, Siamese 287 | Egyptian cat 288 | cougar, puma, catamount, mountain lion, painter, panther, Felis concolor 289 | lynx, catamount 290 | leopard, Panthera pardus 291 | snow leopard, ounce, Panthera uncia 292 | jaguar, panther, Panthera onca, Felis onca 293 | lion, king of beasts, Panthera leo 294 | tiger, Panthera tigris 295 | cheetah, chetah, Acinonyx jubatus 296 | brown bear, bruin, Ursus arctos 297 | American black bear, black bear, Ursus americanus, Euarctos americanus 298 | ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus 299 | sloth bear, Melursus ursinus, Ursus ursinus 300 | mongoose 301 | meerkat, mierkat 302 | tiger beetle 303 | ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle 304 | ground beetle, carabid beetle 305 | long-horned beetle, longicorn, longicorn beetle 306 | leaf beetle, chrysomelid 307 | dung beetle 308 | rhinoceros beetle 309 | weevil 310 | fly 311 | bee 312 | ant, emmet, pismire 313 | grasshopper, hopper 314 | cricket 315 | walking stick, walkingstick, stick insect 316 | cockroach, roach 317 | mantis, mantid 318 | cicada, cicala 319 | leafhopper 320 | lacewing, lacewing fly 321 | dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk 322 | damselfly 323 | admiral 324 | ringlet, ringlet butterfly 325 | monarch, monarch butterfly, milkweed butterfly, Danaus plexippus 326 | cabbage butterfly 327 | sulphur butterfly, sulfur butterfly 328 | lycaenid, lycaenid butterfly 329 | starfish, sea star 330 | sea urchin 331 | sea cucumber, holothurian 332 | wood rabbit, cottontail, cottontail rabbit 333 | hare 334 | Angora, Angora rabbit 335 | hamster 336 | porcupine, hedgehog 337 | fox squirrel, eastern fox squirrel, Sciurus niger 338 | marmot 339 | beaver 340 | guinea pig, Cavia cobaya 341 | sorrel 342 | zebra 343 | hog, pig, grunter, squealer, Sus scrofa 344 | wild boar, boar, Sus scrofa 345 | warthog 346 | hippopotamus, hippo, river horse, Hippopotamus amphibius 347 | ox 348 | water buffalo, water ox, Asiatic buffalo, Bubalus bubalis 349 | bison 350 | ram, tup 351 | bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis 352 | ibex, Capra ibex 353 | hartebeest 354 | impala, Aepyceros melampus 355 | gazelle 356 | Arabian camel, dromedary, Camelus dromedarius 357 | llama 358 | weasel 359 | mink 360 | polecat, fitch, foulmart, foumart, Mustela putorius 361 | black-footed ferret, ferret, Mustela nigripes 362 | otter 363 | skunk, polecat, wood pussy 364 | badger 365 | armadillo 366 | three-toed sloth, ai, Bradypus tridactylus 367 | orangutan, orang, orangutang, Pongo pygmaeus 368 | gorilla, Gorilla gorilla 369 | chimpanzee, chimp, Pan troglodytes 370 | gibbon, Hylobates lar 371 | siamang, Hylobates syndactylus, Symphalangus syndactylus 372 | guenon, guenon monkey 373 | patas, hussar monkey, Erythrocebus patas 374 | baboon 375 | macaque 376 | langur 377 | colobus, colobus monkey 378 | proboscis monkey, Nasalis larvatus 379 | marmoset 380 | capuchin, ringtail, Cebus capucinus 381 | howler monkey, howler 382 | titi, titi monkey 383 | spider monkey, Ateles geoffroyi 384 | squirrel monkey, Saimiri sciureus 385 | Madagascar cat, ring-tailed lemur, Lemur catta 386 | indri, indris, Indri indri, Indri brevicaudatus 387 | Indian elephant, Elephas maximus 388 | African elephant, Loxodonta africana 389 | lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens 390 | giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca 391 | barracouta, snoek 392 | eel 393 | coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch 394 | rock beauty, Holocanthus tricolor 395 | anemone fish 396 | sturgeon 397 | gar, garfish, garpike, billfish, Lepisosteus osseus 398 | lionfish 399 | puffer, pufferfish, blowfish, globefish 400 | abacus 401 | abaya 402 | academic gown, academic robe, judge's robe 403 | accordion, piano accordion, squeeze box 404 | acoustic guitar 405 | aircraft carrier, carrier, flattop, attack aircraft carrier 406 | airliner 407 | airship, dirigible 408 | altar 409 | ambulance 410 | amphibian, amphibious vehicle 411 | analog clock 412 | apiary, bee house 413 | apron 414 | ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin 415 | assault rifle, assault gun 416 | backpack, back pack, knapsack, packsack, rucksack, haversack 417 | bakery, bakeshop, bakehouse 418 | balance beam, beam 419 | balloon 420 | ballpoint, ballpoint pen, ballpen, Biro 421 | Band Aid 422 | banjo 423 | bannister, banister, balustrade, balusters, handrail 424 | barbell 425 | barber chair 426 | barbershop 427 | barn 428 | barometer 429 | barrel, cask 430 | barrow, garden cart, lawn cart, wheelbarrow 431 | baseball 432 | basketball 433 | bassinet 434 | bassoon 435 | bathing cap, swimming cap 436 | bath towel 437 | bathtub, bathing tub, bath, tub 438 | beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon 439 | beacon, lighthouse, beacon light, pharos 440 | beaker 441 | bearskin, busby, shako 442 | beer bottle 443 | beer glass 444 | bell cote, bell cot 445 | bib 446 | bicycle-built-for-two, tandem bicycle, tandem 447 | bikini, two-piece 448 | binder, ring-binder 449 | binoculars, field glasses, opera glasses 450 | birdhouse 451 | boathouse 452 | bobsled, bobsleigh, bob 453 | bolo tie, bolo, bola tie, bola 454 | bonnet, poke bonnet 455 | bookcase 456 | bookshop, bookstore, bookstall 457 | bottlecap 458 | bow 459 | bow tie, bow-tie, bowtie 460 | brass, memorial tablet, plaque 461 | brassiere, bra, bandeau 462 | breakwater, groin, groyne, mole, bulwark, seawall, jetty 463 | breastplate, aegis, egis 464 | broom 465 | bucket, pail 466 | buckle 467 | bulletproof vest 468 | bullet train, bullet 469 | butcher shop, meat market 470 | cab, hack, taxi, taxicab 471 | caldron, cauldron 472 | candle, taper, wax light 473 | cannon 474 | canoe 475 | can opener, tin opener 476 | cardigan 477 | car mirror 478 | carousel, carrousel, merry-go-round, roundabout, whirligig 479 | carpenter's kit, tool kit 480 | carton 481 | car wheel 482 | cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM 483 | cassette 484 | cassette player 485 | castle 486 | catamaran 487 | CD player 488 | cello, violoncello 489 | cellular telephone, cellular phone, cellphone, cell, mobile phone 490 | chain 491 | chainlink fence 492 | chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour 493 | chain saw, chainsaw 494 | chest 495 | chiffonier, commode 496 | chime, bell, gong 497 | china cabinet, china closet 498 | Christmas stocking 499 | church, church building 500 | cinema, movie theater, movie theatre, movie house, picture palace 501 | cleaver, meat cleaver, chopper 502 | cliff dwelling 503 | cloak 504 | clog, geta, patten, sabot 505 | cocktail shaker 506 | coffee mug 507 | coffeepot 508 | coil, spiral, volute, whorl, helix 509 | combination lock 510 | computer keyboard, keypad 511 | confectionery, confectionary, candy store 512 | container ship, containership, container vessel 513 | convertible 514 | corkscrew, bottle screw 515 | cornet, horn, trumpet, trump 516 | cowboy boot 517 | cowboy hat, ten-gallon hat 518 | cradle 519 | crane 520 | crash helmet 521 | crate 522 | crib, cot 523 | Crock Pot 524 | croquet ball 525 | crutch 526 | cuirass 527 | dam, dike, dyke 528 | desk 529 | desktop computer 530 | dial telephone, dial phone 531 | diaper, nappy, napkin 532 | digital clock 533 | digital watch 534 | dining table, board 535 | dishrag, dishcloth 536 | dishwasher, dish washer, dishwashing machine 537 | disk brake, disc brake 538 | dock, dockage, docking facility 539 | dogsled, dog sled, dog sleigh 540 | dome 541 | doormat, welcome mat 542 | drilling platform, offshore rig 543 | drum, membranophone, tympan 544 | drumstick 545 | dumbbell 546 | Dutch oven 547 | electric fan, blower 548 | electric guitar 549 | electric locomotive 550 | entertainment center 551 | envelope 552 | espresso maker 553 | face powder 554 | feather boa, boa 555 | file, file cabinet, filing cabinet 556 | fireboat 557 | fire engine, fire truck 558 | fire screen, fireguard 559 | flagpole, flagstaff 560 | flute, transverse flute 561 | folding chair 562 | football helmet 563 | forklift 564 | fountain 565 | fountain pen 566 | four-poster 567 | freight car 568 | French horn, horn 569 | frying pan, frypan, skillet 570 | fur coat 571 | garbage truck, dustcart 572 | gasmask, respirator, gas helmet 573 | gas pump, gasoline pump, petrol pump, island dispenser 574 | goblet 575 | go-kart 576 | golf ball 577 | golfcart, golf cart 578 | gondola 579 | gong, tam-tam 580 | gown 581 | grand piano, grand 582 | greenhouse, nursery, glasshouse 583 | grille, radiator grille 584 | grocery store, grocery, food market, market 585 | guillotine 586 | hair slide 587 | hair spray 588 | half track 589 | hammer 590 | hamper 591 | hand blower, blow dryer, blow drier, hair dryer, hair drier 592 | hand-held computer, hand-held microcomputer 593 | handkerchief, hankie, hanky, hankey 594 | hard disc, hard disk, fixed disk 595 | harmonica, mouth organ, harp, mouth harp 596 | harp 597 | harvester, reaper 598 | hatchet 599 | holster 600 | home theater, home theatre 601 | honeycomb 602 | hook, claw 603 | hoopskirt, crinoline 604 | horizontal bar, high bar 605 | horse cart, horse-cart 606 | hourglass 607 | iPod 608 | iron, smoothing iron 609 | jack-o'-lantern 610 | jean, blue jean, denim 611 | jeep, landrover 612 | jersey, T-shirt, tee shirt 613 | jigsaw puzzle 614 | jinrikisha, ricksha, rickshaw 615 | joystick 616 | kimono 617 | knee pad 618 | knot 619 | lab coat, laboratory coat 620 | ladle 621 | lampshade, lamp shade 622 | laptop, laptop computer 623 | lawn mower, mower 624 | lens cap, lens cover 625 | letter opener, paper knife, paperknife 626 | library 627 | lifeboat 628 | lighter, light, igniter, ignitor 629 | limousine, limo 630 | liner, ocean liner 631 | lipstick, lip rouge 632 | Loafer 633 | lotion 634 | loudspeaker, speaker, speaker unit, loudspeaker system, speaker system 635 | loupe, jeweler's loupe 636 | lumbermill, sawmill 637 | magnetic compass 638 | mailbag, postbag 639 | mailbox, letter box 640 | maillot 641 | maillot, tank suit 642 | manhole cover 643 | maraca 644 | marimba, xylophone 645 | mask 646 | matchstick 647 | maypole 648 | maze, labyrinth 649 | measuring cup 650 | medicine chest, medicine cabinet 651 | megalith, megalithic structure 652 | microphone, mike 653 | microwave, microwave oven 654 | military uniform 655 | milk can 656 | minibus 657 | miniskirt, mini 658 | minivan 659 | missile 660 | mitten 661 | mixing bowl 662 | mobile home, manufactured home 663 | Model T 664 | modem 665 | monastery 666 | monitor 667 | moped 668 | mortar 669 | mortarboard 670 | mosque 671 | mosquito net 672 | motor scooter, scooter 673 | mountain bike, all-terrain bike, off-roader 674 | mountain tent 675 | mouse, computer mouse 676 | mousetrap 677 | moving van 678 | muzzle 679 | nail 680 | neck brace 681 | necklace 682 | nipple 683 | notebook, notebook computer 684 | obelisk 685 | oboe, hautboy, hautbois 686 | ocarina, sweet potato 687 | odometer, hodometer, mileometer, milometer 688 | oil filter 689 | organ, pipe organ 690 | oscilloscope, scope, cathode-ray oscilloscope, CRO 691 | overskirt 692 | oxcart 693 | oxygen mask 694 | packet 695 | paddle, boat paddle 696 | paddlewheel, paddle wheel 697 | padlock 698 | paintbrush 699 | pajama, pyjama, pj's, jammies 700 | palace 701 | panpipe, pandean pipe, syrinx 702 | paper towel 703 | parachute, chute 704 | parallel bars, bars 705 | park bench 706 | parking meter 707 | passenger car, coach, carriage 708 | patio, terrace 709 | pay-phone, pay-station 710 | pedestal, plinth, footstall 711 | pencil box, pencil case 712 | pencil sharpener 713 | perfume, essence 714 | Petri dish 715 | photocopier 716 | pick, plectrum, plectron 717 | pickelhaube 718 | picket fence, paling 719 | pickup, pickup truck 720 | pier 721 | piggy bank, penny bank 722 | pill bottle 723 | pillow 724 | ping-pong ball 725 | pinwheel 726 | pirate, pirate ship 727 | pitcher, ewer 728 | plane, carpenter's plane, woodworking plane 729 | planetarium 730 | plastic bag 731 | plate rack 732 | plow, plough 733 | plunger, plumber's helper 734 | Polaroid camera, Polaroid Land camera 735 | pole 736 | police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria 737 | poncho 738 | pool table, billiard table, snooker table 739 | pop bottle, soda bottle 740 | pot, flowerpot 741 | potter's wheel 742 | power drill 743 | prayer rug, prayer mat 744 | printer 745 | prison, prison house 746 | projectile, missile 747 | projector 748 | puck, hockey puck 749 | punching bag, punch bag, punching ball, punchball 750 | purse 751 | quill, quill pen 752 | quilt, comforter, comfort, puff 753 | racer, race car, racing car 754 | racket, racquet 755 | radiator 756 | radio, wireless 757 | radio telescope, radio reflector 758 | rain barrel 759 | recreational vehicle, RV, R.V. 760 | reel 761 | reflex camera 762 | refrigerator, icebox 763 | remote control, remote 764 | restaurant, eating house, eating place, eatery 765 | revolver, six-gun, six-shooter 766 | rifle 767 | rocking chair, rocker 768 | rotisserie 769 | rubber eraser, rubber, pencil eraser 770 | rugby ball 771 | rule, ruler 772 | running shoe 773 | safe 774 | safety pin 775 | saltshaker, salt shaker 776 | sandal 777 | sarong 778 | sax, saxophone 779 | scabbard 780 | scale, weighing machine 781 | school bus 782 | schooner 783 | scoreboard 784 | screen, CRT screen 785 | screw 786 | screwdriver 787 | seat belt, seatbelt 788 | sewing machine 789 | shield, buckler 790 | shoe shop, shoe-shop, shoe store 791 | shoji 792 | shopping basket 793 | shopping cart 794 | shovel 795 | shower cap 796 | shower curtain 797 | ski 798 | ski mask 799 | sleeping bag 800 | slide rule, slipstick 801 | sliding door 802 | slot, one-armed bandit 803 | snorkel 804 | snowmobile 805 | snowplow, snowplough 806 | soap dispenser 807 | soccer ball 808 | sock 809 | solar dish, solar collector, solar furnace 810 | sombrero 811 | soup bowl 812 | space bar 813 | space heater 814 | space shuttle 815 | spatula 816 | speedboat 817 | spider web, spider's web 818 | spindle 819 | sports car, sport car 820 | spotlight, spot 821 | stage 822 | steam locomotive 823 | steel arch bridge 824 | steel drum 825 | stethoscope 826 | stole 827 | stone wall 828 | stopwatch, stop watch 829 | stove 830 | strainer 831 | streetcar, tram, tramcar, trolley, trolley car 832 | stretcher 833 | studio couch, day bed 834 | stupa, tope 835 | submarine, pigboat, sub, U-boat 836 | suit, suit of clothes 837 | sundial 838 | sunglass 839 | sunglasses, dark glasses, shades 840 | sunscreen, sunblock, sun blocker 841 | suspension bridge 842 | swab, swob, mop 843 | sweatshirt 844 | swimming trunks, bathing trunks 845 | swing 846 | switch, electric switch, electrical switch 847 | syringe 848 | table lamp 849 | tank, army tank, armored combat vehicle, armoured combat vehicle 850 | tape player 851 | teapot 852 | teddy, teddy bear 853 | television, television system 854 | tennis ball 855 | thatch, thatched roof 856 | theater curtain, theatre curtain 857 | thimble 858 | thresher, thrasher, threshing machine 859 | throne 860 | tile roof 861 | toaster 862 | tobacco shop, tobacconist shop, tobacconist 863 | toilet seat 864 | torch 865 | totem pole 866 | tow truck, tow car, wrecker 867 | toyshop 868 | tractor 869 | trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi 870 | tray 871 | trench coat 872 | tricycle, trike, velocipede 873 | trimaran 874 | tripod 875 | triumphal arch 876 | trolleybus, trolley coach, trackless trolley 877 | trombone 878 | tub, vat 879 | turnstile 880 | typewriter keyboard 881 | umbrella 882 | unicycle, monocycle 883 | upright, upright piano 884 | vacuum, vacuum cleaner 885 | vase 886 | vault 887 | velvet 888 | vending machine 889 | vestment 890 | viaduct 891 | violin, fiddle 892 | volleyball 893 | waffle iron 894 | wall clock 895 | wallet, billfold, notecase, pocketbook 896 | wardrobe, closet, press 897 | warplane, military plane 898 | washbasin, handbasin, washbowl, lavabo, wash-hand basin 899 | washer, automatic washer, washing machine 900 | water bottle 901 | water jug 902 | water tower 903 | whiskey jug 904 | whistle 905 | wig 906 | window screen 907 | window shade 908 | Windsor tie 909 | wine bottle 910 | wing 911 | wok 912 | wooden spoon 913 | wool, woolen, woollen 914 | worm fence, snake fence, snake-rail fence, Virginia fence 915 | wreck 916 | yawl 917 | yurt 918 | web site, website, internet site, site 919 | comic book 920 | crossword puzzle, crossword 921 | street sign 922 | traffic light, traffic signal, stoplight 923 | book jacket, dust cover, dust jacket, dust wrapper 924 | menu 925 | plate 926 | guacamole 927 | consomme 928 | hot pot, hotpot 929 | trifle 930 | ice cream, icecream 931 | ice lolly, lolly, lollipop, popsicle 932 | French loaf 933 | bagel, beigel 934 | pretzel 935 | cheeseburger 936 | hotdog, hot dog, red hot 937 | mashed potato 938 | head cabbage 939 | broccoli 940 | cauliflower 941 | zucchini, courgette 942 | spaghetti squash 943 | acorn squash 944 | butternut squash 945 | cucumber, cuke 946 | artichoke, globe artichoke 947 | bell pepper 948 | cardoon 949 | mushroom 950 | Granny Smith 951 | strawberry 952 | orange 953 | lemon 954 | fig 955 | pineapple, ananas 956 | banana 957 | jackfruit, jak, jack 958 | custard apple 959 | pomegranate 960 | hay 961 | carbonara 962 | chocolate sauce, chocolate syrup 963 | dough 964 | meat loaf, meatloaf 965 | pizza, pizza pie 966 | potpie 967 | burrito 968 | red wine 969 | espresso 970 | cup 971 | eggnog 972 | alp 973 | bubble 974 | cliff, drop, drop-off 975 | coral reef 976 | geyser 977 | lakeside, lakeshore 978 | promontory, headland, head, foreland 979 | sandbar, sand bar 980 | seashore, coast, seacoast, sea-coast 981 | valley, vale 982 | volcano 983 | ballplayer, baseball player 984 | groom, bridegroom 985 | scuba diver 986 | rapeseed 987 | daisy 988 | yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum 989 | corn 990 | acorn 991 | hip, rose hip, rosehip 992 | buckeye, horse chestnut, conker 993 | coral fungus 994 | agaric 995 | gyromitra 996 | stinkhorn, carrion fungus 997 | earthstar 998 | hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa 999 | bolete 1000 | ear, spike, capitulum 1001 | toilet tissue, toilet paper, bathroom tissue 1002 | --------------------------------------------------------------------------------