@@ -897,12 +897,6 @@ std::shared_ptr<Monitor> Monitor::Load(unsigned int p_id, bool load_zones,
897897}
898898
899899bool Monitor::connect () {
900- ReloadZones ();
901- if (zones.size () != zone_count) {
902- Warning (" Monitor %d has incorrect zone_count %d != %zu" , id, zone_count,
903- zones.size ());
904- zone_count = zones.size ();
905- }
906900 if (mem_ptr != nullptr ) {
907901 Warning (" Already connected. Please call disconnect first." );
908902 }
@@ -1136,6 +1130,12 @@ bool Monitor::connect() {
11361130
11371131 ReloadLinkedMonitors ();
11381132
1133+ // Normally we trust ZoneCount in the monitor field. In a healthy db it should be correct.
1134+ ReloadZones ();
1135+ if (zones.size () != zone_count) {
1136+ Warning (" Monitor %d has incorrect zone_count %d != %zu" , id, zone_count, zones.size ());
1137+ zone_count = zones.size ();
1138+ }
11391139
11401140 if (RTSP2Web_enabled) {
11411141 RTSP2Web_Manager = new RTSP2WebManager (this );
@@ -2441,7 +2441,7 @@ int Monitor::Analyse() {
24412441 shared_data->last_read_index = index;
24422442 shared_data->analysis_image_count = analysis_image_count;
24432443 } else if (objectdetection == OBJECT_DETECTION_NONE ) {
2444- if (1 and packet->analysis_image ) {
2444+ if (packet->analysis_image ) {
24452445 analysis_image_buffer[index]->Assign (*packet->analysis_image );
24462446 analysis_image_pixelformats[index] = packet->analysis_image ->AVPixFormat ();
24472447 Debug (1 , " image format %d, for index %d" , analysis_image_pixelformats[index], index);
@@ -2456,7 +2456,7 @@ int Monitor::Analyse() {
24562456 analysis_image_buffer[index]->Assign (packet->out_frame .get ());
24572457 analysis_image_pixelformats[index] = static_cast <AVPixelFormat>(packet->out_frame ->format );
24582458 } else {
2459- Error ( " Unable to find an image to assign for index %d packet %d" , index, packet->image_index );
2459+ Debug ( 1 , " Unable to find an image to assign for index %d packet %d" , index, packet->image_index );
24602460 }
24612461 shared_analysis_timestamps[index] = zm::chrono::duration_cast<timeval>(packet->timestamp .time_since_epoch ());
24622462 shared_data->last_analysis_index = index;
@@ -2643,49 +2643,56 @@ std::pair<int, std::string> Monitor::Analyse_UVICORN(std::shared_ptr<ZMPacket> p
26432643
26442644 // Image img(packet->in_frame.get(), 640, 640); // copy, since we are scaling, maybe better to take from in_frame
26452645
2646- uint8_t *img_buffer = new uint8_t [img.Size ()];
2647- img.EncodeJpeg (static_cast <JOCTET *>(img_buffer), &img_buffer_size);
2646+ std::vector<uint8_t > img_buffer;
2647+ img_buffer.reserve (img.Size ());
2648+
2649+ img.EncodeJpeg (static_cast <JOCTET *>(img_buffer.data ()), &img_buffer_size);
26482650
26492651 endtime = std::chrono::system_clock::now ();
26502652 Debug (1 , " UVICORN took: %.3f seconds to scale file size is %zu." , FPSeconds (endtime - partial_starttime).count (), img_buffer_size);
26512653 partial_starttime = endtime;
26522654 //
26532655 std::string response;
26542656 response.reserve (4096 );
2657+
26552658 std::string endpoint = stringtf (" http://127.0.0.1:8000/predict/?camera_id=%d" , id);
2656- curl_easy_setopt (curl, CURLOPT_FAILONERROR , 1 );
2657- // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
2658- curl_easy_setopt (curl, CURLOPT_URL , endpoint.c_str ());
2659-
2660- curl_mime *mime = nullptr ;
2661- curl_mimepart *part = nullptr ;
2662- mime = curl_mime_init (curl);
2663- part = curl_mime_addpart (mime);
2664-
2665- struct transfer tr = {img_buffer, img_buffer_size, 0 };
2666- curl_mime_data_cb (part, (size_t )img_buffer_size, ReadCallback, NULL , NULL , &tr);
2667- // curl_mime_data(part, (const char *)img_buffer, img_buffer_size);
2668- curl_mime_name (part, " file" );
2669- curl_mime_filename (part, stringtf (" camera%d.jpg" , id).c_str ());
2670-
2671- curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION , WriteCallback);
2672- curl_easy_setopt (curl, CURLOPT_WRITEDATA , &response);
2673- curl_easy_setopt (curl, CURLOPT_MIMEPOST , mime);
2674- curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST , 0 );
2675- curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER , 0 );
2676- curl_easy_setopt (curl, CURLOPT_TIMEOUT , 10 ); // timeout in seconds
2677- CURLcode res = curl_easy_perform (curl);
2678-
2679- if (res != CURLE_OK ) {
2680- Warning (" CURL: Attempted to send to %s and got %s" , endpoint.c_str (), curl_easy_strerror (res));
2681- return std::make_pair (motion_score, cause);
2659+ if (endpoint.find (" http" ) != std::string::npos) {
2660+ curl_easy_setopt (curl, CURLOPT_FAILONERROR , 1 );
2661+ // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
2662+ curl_easy_setopt (curl, CURLOPT_URL , endpoint.c_str ());
2663+
2664+ curl_mime *mime = nullptr ;
2665+ curl_mimepart *part = nullptr ;
2666+ mime = curl_mime_init (curl);
2667+ part = curl_mime_addpart (mime);
2668+
2669+ struct transfer tr = {img_buffer.data (), img_buffer_size, 0 };
2670+ curl_mime_data_cb (part, (size_t )img_buffer_size, ReadCallback, NULL , NULL , &tr);
2671+ // curl_mime_data(part, (const char *)img_buffer, img_buffer_size);
2672+ curl_mime_name (part, " file" );
2673+ curl_mime_filename (part, stringtf (" camera%d.jpg" , id).c_str ());
2674+
2675+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION , WriteCallback);
2676+ curl_easy_setopt (curl, CURLOPT_WRITEDATA , &response);
2677+ curl_easy_setopt (curl, CURLOPT_MIMEPOST , mime);
2678+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYHOST , 0 );
2679+ curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER , 0 );
2680+ curl_easy_setopt (curl, CURLOPT_TIMEOUT , 10 ); // timeout in seconds
2681+ CURLcode res = curl_easy_perform (curl);
2682+ curl_mime_free (mime);
2683+
2684+ if (res != CURLE_OK ) {
2685+ Warning (" CURL: Attempted to send to %s and got %s" , endpoint.c_str (), curl_easy_strerror (res));
2686+ return std::make_pair (motion_score, cause);
2687+ }
2688+ } else {
2689+ // Write to local hotfolder
2690+ img.WriteJpeg (endpoint + stringtf (" /camera%d.jpg" , id));
26822691 }
26832692 endtime = std::chrono::system_clock::now ();
26842693 Debug (1 , " UVICORN took: %.3f seconds to send." , FPSeconds (endtime - partial_starttime).count ());
26852694 partial_starttime = endtime;
26862695 // Debug(1, "CURL: Success sending to %s, response is %s", endpoint.c_str(), response.c_str());
2687- curl_mime_free (mime);
2688- delete[] img_buffer;
26892696
26902697 nlohmann::json detections = nlohmann::json::parse (response);
26912698 Debug (1 , " CURL detections %s" , detections.dump ().c_str ());
@@ -2722,7 +2729,7 @@ std::pair<int, std::string> Monitor::Analyse_MotionDetection(std::shared_ptr<ZMP
27222729 std::string cause = " " ;
27232730
27242731 if (!(packet->in_frame or packet->image )) {
2725- Error ( " no image so skipping motion detection" );
2732+ Debug ( 1 , " no image so skipping motion detection" );
27262733 return std::make_pair (motion_score, cause);
27272734 } // end if has image
27282735
0 commit comments