Skip to content

Atlas200dk/sample-videoanalysisperson

Repository files navigation

English|中文

People Detection

Developers can deploy the application on the Atlas 200 DK or the AI acceleration cloud server to decode the local MP4 file or RTSP video streams, detect pedestrians, and human faces in video frames, predict their attributes, generate structured information, and send the structured information to the server for storage and display.

The applications in the current version branch adapt to DDK&RunTime 1.32.0.0 and later.

Prerequisites

Before deploying this sample, ensure that:

  • Mind Studio has been installed.
  • The Atlas 200 DK developer board has been connected to Mind Studio, the cross compiler has been installed, the SD card has been prepared, and basic information has been configured.

Deployment

You can use either of the following methods:

  1. Quick deployment: visit https://github.com/Atlas200dk/faster-deploy.

    NOTE:

    • The quick deployment script can be used to deploy multiple samples rapidly. Select videoanalysisperson.
    • The quick deployment script automatically completes code download, model conversion, and environment variable configuration. To learn about the detailed deployment process, go to 2. Common deployment.
  2. Common deployment: visit https://github.com/Atlas200dk/sample-README/tree/master/sample-videoanalysisperson.

    NOTE:

    • In this deployment mode, you need to manually download code, convert models, and configure environment variables.

Building a Project

  1. Open the project.

    Go to the directory that stores the decompressed installation package as the Mind Studio installation user in CLI mode, for example, $HOME/MindStudio-ubuntu/bin. Run the following command to start Mind Studio:

    ./MindStudio.sh

    Open the sample-videoanalysisperson project, as shown in Figure 1.

    Figure 1 Opening the videoanalysisperson project

  2. Configure project information in the src/param_configure.conf file.

    Figure 2 Configuration file path

    The default configurations of the configuration file are as follows:

    remote_host=192.168.1.2
    presenter_view_app_name=video
    video_path_of_host=/home/HwHiAiUser/person.mp4
    rtsp_video_stream=
    
    • remote_host: IP address of the Atlas 200 DK developer board

    • presenter_view_app_name: value of View Name on the Presenter Server page, which must be unique. The value consists of 3 to 20 characters and supports only uppercase letters, lowercase letters, digits, and underscores (_).

    • video_path_of_host: absolute path of a video file on the host side

    • rtsp_video_stream: URL of RTSP video streams

    Sample of video file configuration:

    remote_host=192.168.1.2
    presenter_view_app_name=video
    video_path_of_host=/home/HwHiAiUser/person.mp4
    rtsp_video_stream=
    

    Sample of RTSP video stream configuration:

    remote_host=192.168.1.2
    presenter_view_app_name=video
    video_path_of_host=
    rtsp_video_stream=rtsp://192.168.2.37:554/cam/realmonitor?channel=1&subtype=0
    

    NOTE:

    • remote_host and presenter_view_app_name must be set. Otherwise, the build fails.
    • Do not use double quotation marks ("") during parameter settings.
    • Either video_path_of_host or rtsp_video_stream must be set.
    • Currently, RTSP video streams support only the rtsp://ip:port/path format. To use URLs in other formats, you need to delete the** IsValidRtsp** function from the video_decode.cpp file or configure the IsValidRtsp function to directly return true to skip regular expression matching.
    • The RTSP stream URL provided in this sample cannot be directly used. If RTSP streams are required, create RTSP streams locally either using LIVE555 or other methods, which must support playback in the VLC. Type the URL of the RTSP video streams in the configuration file.
    • Modify the default configurations as required.
  3. Run the deploy.sh script to adjust configuration parameters and download and compile the third-party library. Open the Terminal window of Mind Studio. By default, the home directory of the code is used. Run the deploy.sh script in the background to deploy the environment, as shown in Figure 3.

    Figure 3 Running the deploy.sh script

    NOTE:

    • During the first deployment, if no third-party library is used, the system automatically downloads and builds the third-party library, which may take a long time. The third-party library can be directly used for the subsequent build.
    • During deployment, select the IP address of the host that communicates with the developer board. Generally, the IP address is that configured for the virtual NIC. If the IP address is in the same network segment as the IP address of the developer board, it is automatically selected for deployment. If they are not in the same network segment, you need to manually type the IP address of the host that communicates with the developer board to complete the deployment.
  4. Start building. Open Mind Studio and choose Build > Build > Build-Configuration from the main menu. The build and run folders are generated in the directory, as shown in Figure 4.

    Figure 4 Build and files generated

    NOTICE:
    When you build a project for the first time, Build > Build is unavailable. You need to choose Build > Edit Build Configuration to set parameters before the build.

  5. Start Presenter Server.

    Open the Terminal window of Mind Studio. By default, under the code path, run the following command to start the Presenter Server program of the people detection application on the server, as shown in Figure 5:

    bash run_present_server.sh

    Figure 5 Starting Presenter Server

    • When the message Please choose one to show the presenter in browser (default: 127.0.0.1): is displayed, type the IP address (usually IP address for accessing Mind Studio) for accessing the Presenter Server service in the browser.

      Select the IP address used by the browser to access the Presenter Server service in Current environment valid ip list, as shown in Figure 6.

      Figure 6 Project deployment

    • When the message Please input an absolute path to storage video analysis data: is displayed, enter the absolute path for storing video analysis data in Mind Studio. The Mind Studio user must have the read and write permissions. If the path does not exist, the script will automatically create it.

    Figure 7 shows that the Presenter Server service has been started successfully.

    Figure 7 Starting the Presenter Server process

    Use the URL shown in the preceding figure to log in to Presenter Server (only Google Chrome is supported). The IP address is that typed in Figure 6 and the default port number is 7011. The following figure indicates that Presenter Server has been started successfully.

    Figure 8 Home page

    The following figure shows the IP address used by Presenter Server and Mind Studio to communicate with the Atlas 200 DK.

    Figure 9 IP address example

    • The IP address of the Atlas 200 DK developer board is 192.168.1.2 (connected in USB mode).
    • The IP address used by Presenter Server to communicate with the Atlas 200 DK is in the same network segment as the IP address of the Atlas 200 DK on the UI Host server, for example, 192.168.1.223.
    • The following is an example of accessing the IP address of Presenter Server using a browser: 10.10.0.1, because Presenter Server and Mind Studio are deployed on the same server, the IP address is also the IP address for accessing the Mind Studio through the browser.
  6. Parse local videos and RTSP video streams using the people detection application.

    • To parse a local video, upload the video file to the host.

      For example, upload the video file person.mp4 to the /home/HwHiAiUser/ directory on the host.

      NOTE:
      H.264 and H.265 MP4 files are supported. If an MP4 file needs to be edited, you are advised to use FFmpeg. If a video file is edited by other tools, FFmpeg may fail to parse the file.

    • If only RTSP video streams need to be parsed, skip this step.

Running

  1. Run the people detection application.

    On the toolbar of Mind Studio, click Run and choose Run > Run 'sample-videoanalysisperson'. As shown in Figure 10, the executable application is running on the developer board.

    Figure 10 Application running

  2. Use the URL displayed upon the start of the Presenter Server service to log in to Presenter Server.

    NOTE:
    Presenter Server of the people detection application can display a maximum of two presenter_view_app_name values at a time.

    The navigation tree on the left displays the app name and channel name of the video. The large image of the extracted video frame and the detected target small image are displayed in the middle. After you click the small image, the detailed inference result and score are displayed on the right.

    This application supports human body attribute detection, and facial attribute detection.

    • Human body attributes include:

      Ages (ages 16–30, 31–45, 46–60 as well as 61 and above); Backpack; Carrying other; Casual lower; Casual upper; Formal lower; Hat; Jacket; Jeans; Leather Shoes; Logo; Short hair/Long hair; Male/Female; Messenger Bag; Muffler; No accessory; No carrying; Plaid; Plastic bags; Sandals; Shoes; Shorts; Short Sleeve; Skirt; Sneaker; Stripes; Sunglasses; Trousers; T-shirt; Upper other; V-Neck.

      In the detailed inference result display area on the video analysis interface, Age, Male/Female, and Short hair/Long hair are mandatory. Other attributes are displayed only when the confidence level is greater than 0.5.

    • Facial attribute detection supports age and gender identification.

Follow-up Operations

  • Stopping the people detection application

    After the video analysis is complete, the application automatically stops and exists, as shown in Figure 11.

    Figure 11 videoperson stopped

  • Stopping the Presenter Server service

    The Presenter Server service is always in running state after being started. To stop the Presenter Server service of the people detection application, perform the following operations:

    Run the following command as the Mind Studio installation user to check the process of the Presenter Server service corresponding to the people detection application:

    ps -ef | grep presenter | grep video_analysis_person

    ascend@ascend-HP-ProDesk-600-G4-PCI-MT:~/sample-videoanalysisperson$ ps -ef | grep presenter | grep video_analysis_car
    ascend 3656 20313 0 15:10 pts/24?? 00:00:00 python3 presenterserver/presenter_server.py --app video_analysis_person
    

    In the preceding information, 3656 indicates the process ID of the Presenter Server service corresponding to the people detection application.

    To stop the service, run the following command:

    kill -9 3656

  • Precautions for restarting the people detection application

    Before restarting the people detection application, ensure that any of the following conditions is met. Otherwise, an error is reported.

    1. The content in the video parsing data storage path must have been cleared.

      For example, the path for storing video parsing data is $HOME/videoperson_storage/video, where $HOME/videoperson_storage is configured when you start the Presenter Server service as pompt ("Please input an absolute path to storage video analysis data"). video is the value of presenter_view_app_name in the configuration file param_configure.conf.

      If this condition is met, you do not need to restart Presenter Server. Instead, choose Run > Run 'sample-videoanalysisperson' to run the application again.

    2. If the video parsing storage path contains data that you want to keep, you can change the value of presenter_view_app_name in the param_configure.conf file, choose Build > Rebuild again on Mind Studio, and then choose Run > Run 'sample-videoanalysisperson'.

      In the following figure, check out the value of presenter_view_app_name in the param_configure.conf file.

      If this condition is met, you do not need to restart Presenter Server.

    3. If you restart Presenter Server and then run the vehicle detection application, change the path for storing video parsing data when restarting Presenter Server (the path must be different from the previous storage path).