2020 * You should have received a copy of the GNU Lesser General Public License
2121 * along with deepdetect. If not, see <http://www.gnu.org/licenses/>.
2222 */
23-
24- #include " deepdetect.h"
25- #include " jsonapi.h"
26- #include " txtinputfileconn.h"
2723#include < gtest/gtest.h>
2824#include < stdio.h>
2925#include < iostream>
3026#include < numeric>
31- #include " backends/torch/native/templates/nbeats.h"
27+ #pragma GCC diagnostic push
28+ #pragma GCC diagnostic ignored "-Wunused-parameter"
29+ #pragma GCC diagnostic ignored "-Wunused-variable"
3230#include < torch/torch.h>
31+ #pragma GCC diagnostic pop
3332#include < rapidjson/istreamwrapper.h>
3433
34+ #include " deepdetect.h"
35+ #include " jsonapi.h"
36+ #include " txtinputfileconn.h"
37+ #include " utils/cv_utils.hpp"
38+ #include " backends/torch/native/templates/nbeats.h"
39+
3540using namespace dd ;
3641
3742static std::string ok_str = " {\" status\" :{\" code\" :200,\" msg\" :\" OK\" }}" ;
@@ -383,6 +388,7 @@ TEST(torchapi, service_predict_object_detection)
383388 " \" best_bbox\" :3}},\" data\" :[\" "
384389 + detect_repo + " cat.jpg\" ]}" ;
385390 joutstr = japi.jrender (japi.service_predict (jpredictstr));
391+ jd = JDoc ();
386392 std::cout << " joutstr=" << joutstr << std::endl;
387393 jd.Parse <rapidjson::kParseNanAndInfFlag >(joutstr.c_str ());
388394
@@ -392,6 +398,26 @@ TEST(torchapi, service_predict_object_detection)
392398
393399 auto &preds_best = jd[" body" ][" predictions" ][0 ][" classes" ];
394400 ASSERT_EQ (preds_best.Size (), 3 );
401+
402+ // base64
403+ cv::Mat img = cv::imread (detect_repo + " cat.jpg" );
404+ std::string b64_str = cv_utils::image_to_base64 (img, " .png" );
405+ jpredictstr = " {\" service\" :\" detectserv\" ,\" parameters\" :{"
406+ " \" input\" :{\" height\" :224,"
407+ " \" width\" :224},\" output\" :{\" bbox\" :true, "
408+ " \" best_bbox\" :3}},\" data\" :[\" "
409+ + b64_str + " \" ]}" ;
410+ joutstr = japi.jrender (japi.service_predict (jpredictstr));
411+ jd = JDoc ();
412+ std::cout << " joutstr=" << joutstr << std::endl;
413+ jd.Parse <rapidjson::kParseNanAndInfFlag >(joutstr.c_str ());
414+
415+ ASSERT_TRUE (!jd.HasParseError ());
416+ ASSERT_EQ (200 , jd[" status" ][" code" ]);
417+ ASSERT_TRUE (jd[" body" ][" predictions" ].IsArray ());
418+
419+ auto &preds_best_b64 = jd[" body" ][" predictions" ][0 ][" classes" ];
420+ ASSERT_EQ (preds_best_b64.Size (), 3 );
395421}
396422
397423TEST (torchapi, service_predict_object_detection_any_size)
0 commit comments