This sample provides reference for you to learn the Ascend AI Software Stack and cannot be used for commercial purposes.
This sample works with CANN 3.3.0 and later versions, and supports Atlas 200 DK and Atlas 300.
Function: detect the presence of a hand in a scene with the Hand_detection.om model.
Input: an image
Output: an images with bounding box for the detected hand in the scene
Before deploying this sample, ensure that:
- The environment has been set up by referring to Environment Preparation and Dependency Installation.
- The development environment and operating environment of the corresponding product have been set up.
-
Make sure you log in to the operating environment (HwHiAiUser)
ssh HwHiAiUser@xxx.xxx.xxx.xxxReplace xxx.xxx.xxx.xxx with the IP address of the operating environment. The IP address of Atlas 200 DK is 192.168.1.2 when it is connected over the USB port, and that of Atlas 300 is the corresponding public network IP address.
cd $HOME
git clone https://github.com/Ascend/samples.git
Only if required libraries are not installed
pip3 install Pillow
pip3 install opencv-python
Ensure you are in the project directory (hand_detection_picture/) and run the following commands in the table to obtain the hand detection model used in the application.
cd $HOME/samples/python/contrib/hand_detection_picture/
| Model | How to Obtain |
|---|---|
| Hand_detection.pb | wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/Hand_detection.pb' -O model/Hand_detection.pb |
| hand.jpg | wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/hand.jpg' -O data/hand.jpg |
| verify.jpg | wget --no-check-certificate 'https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/hand_detection_picture/verify.jpg' -O data/verify.jpg |
Note: Ensure that the environment variables have been configured in Environment Preparation and Dependency Installation.
-
Set the LD_LIBRARY_PATH environment variable.
The LD_LIBRARY_PATH environment variable conflicts with the sample when Ascend Tensor Compiler (ATC) is used. Therefore, you need to set this environment variable separately in the command line to facilitate modification.
export LD_LIBRARY_PATH=${install_path}/compiler/lib64 -
Go to the project directory (hand_detection) and run the model conversion command to convert the model:
atc --model=model/Hand_detection.pb --framework=3 --output=model/Hand_detection --soc_version=Ascend310 --input_shape="image_tensor:1,300,300,3" --input_format=NHWC --output_type=FP32
cd $HOME/samples/python/contrib/hand_detection_picture/src
python3 hand_detection.py
See output/output.jpg to see detection result
After the execution is complete, the inference result is displayed on the CLI of the operating environment.
