We have connected our independently developed pedestrian analysis and detection function with the ticketing system of a scenic spot, and run the test program. We also tested the pedestrian detection feature internally before launching it, and found that the traffic analysis program only worked when the page was open.

Start the Python program, set RTSP in it, set the port number of a program, use Python command tool to start analysis and check the traffic, and open the following picture on the web page, which can normally detect and analyze the traffic:

However, if you close the web page, the program analysis will stop, and the application console will display an error “Stopping camera Thread due to inactivity.” And the statistical data will not be printed.

However, we found that the program did not display red errors, indicating that the program was not stopped by a crash. Search for the keyword “Stopping camera thread due to inactivity.” in the file “base_camera. Py”, you will find the keyword output by the program.

This program determines what it means: stop the thread operation in the last 10 seconds without any client requests. So this code is the key, the data is returned to the client request, as long as there is no client requester analysis will terminate.

So without affecting the program problem, just remove the following code:

if time.time() - BaseCamera.last_access > 10:
    frames_iterator.close()
    print('Stopping camera thread due to inactivity.')
    break
Copy the code

Delete and test again. First open a web client, the analysis of the screen will be normal display, and then the web client closed, that is, do not request, after this modification of the program will be normal analysis and print analysis of the data.