From 5c55137687e11bb4cdaef92a48a4889041167960 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Sat, 12 Jan 2019 02:56:30 +0300 Subject: [PATCH] Minor fix --- src/http_stream.cpp | 6 +++--- src/network.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/http_stream.cpp b/src/http_stream.cpp index 65beba06..ebe9664b 100644 --- a/src/http_stream.cpp +++ b/src/http_stream.cpp @@ -413,6 +413,7 @@ public: //"Content-Type: multipart/x-mixed-replace; boundary=boundary\r\n" "\r\n", 0); _write(client, "[\n", 0); // open JSON array + int n = _write(client, outputbuf, outlen); cerr << "JSON_sender: new client " << client << endl; } else // existing client, just stream pix @@ -424,6 +425,7 @@ public: //sprintf(head, "\r\nContent-Length: %zu\r\n\r\n", outlen); //sprintf(head, "--boundary\r\nContent-Type: application/json\r\nContent-Length: %zu\r\n\r\n", outlen); //_write(s, head, 0); + if(!close_all_sockets) _write(s, ", \n", 0); int n = _write(s, outputbuf, outlen); if (n < outlen) { @@ -451,9 +453,7 @@ public: void send_json(detection *dets, int nboxes, int classes, char **names, long long int frame_id, int port, int timeout) { static JSON_sender js(port, timeout); - static char *send_buf = NULL; - if (send_buf) js.write(", \n"); - send_buf = detection_to_json(dets, nboxes, classes, names, frame_id, NULL); + char *send_buf = detection_to_json(dets, nboxes, classes, names, frame_id, NULL); js.write(send_buf); std::cout << " JSON-stream sent. \n"; diff --git a/src/network.c b/src/network.c index fc62ea79..b748a857 100644 --- a/src/network.c +++ b/src/network.c @@ -692,7 +692,7 @@ char *detection_to_json(detection *dets, int nboxes, int classes, char **names, //sprintf(buf, "{\"image_id\":%d, \"category_id\":%d, \"bbox\":[%f, %f, %f, %f], \"score\":%f}", // image_id, j, dets[i].bbox.x, dets[i].bbox.y, dets[i].bbox.w, dets[i].bbox.h, dets[i].prob[j]); - sprintf(buf, " {\"class_id\":%d, \"name\":\"%s\", \"relative coordinates\":{\"center_x\":%f, \"center_y\":%f, \"width\":%f, \"height\":%f}, \"confidence\":%f}", + sprintf(buf, " {\"class_id\":%d, \"name\":\"%s\", \"relative_coordinates\":{\"center_x\":%f, \"center_y\":%f, \"width\":%f, \"height\":%f}, \"confidence\":%f}", j, names[j], dets[i].bbox.x, dets[i].bbox.y, dets[i].bbox.w, dets[i].bbox.h, dets[i].prob[j]); int send_buf_len = strlen(send_buf);