@@ -262,13 +262,18 @@ maix_image &maix_image::_open_file(std::string path)
262
262
this ->v_close ();
263
263
libmaix_image_t *tmp_img = NULL ;
264
264
libmaix_err_t err = libmaix_cv_image_open_file (&tmp_img, path.c_str ());
265
- if (LIBMAIX_ERR_NOT_EXEC == err)
265
+ if (LIBMAIX_ERR_NOT_EXEC == err) // maybe is bytes jpg.
266
266
{
267
267
try
268
268
{
269
269
// maybe is jpg or bmp bytes
270
270
cv::Mat tmp (1 , path.size (), CV_8U, (char *)path.data ());
271
271
cv::Mat image = cv::imdecode (tmp, cv::IMREAD_COLOR);
272
+ if (image.empty ()) {
273
+ printf (" [image.open] %s file does not exist\r\n " , path.c_str ());
274
+ this ->v_close ();
275
+ return *this ;
276
+ }
272
277
cv::cvtColor (image, image, cv::ColorConversionCodes::COLOR_BGR2RGB);
273
278
tmp_img = libmaix_image_create (image.cols , image.rows , LIBMAIX_IMAGE_MODE_RGB888, LIBMAIX_IMAGE_LAYOUT_HWC, NULL , true );
274
279
memcpy (tmp_img->data , image.data , tmp_img->width * tmp_img->height * 3 );
@@ -298,7 +303,7 @@ py::object maix_image::_to_py(std::string im)
298
303
{
299
304
if (NULL == this ->_img )
300
305
{
301
- py::print (" no img " );
306
+ py::print (" [image] is empty ! " );
302
307
return py::none ();
303
308
}
304
309
if (im == " maix_image" )
@@ -381,7 +386,7 @@ void maix_image::_show()
381
386
{
382
387
if (NULL == this ->_img )
383
388
{
384
- py::print (" no img " );
389
+ py::print (" [image] is empty ! " );
385
390
return ;
386
391
}
387
392
auto _maix_display = py::module::import (" _maix_display" );
@@ -480,7 +485,7 @@ maix_image &maix_image::_resize(int dst_w, int dst_h, int func, int padding, std
480
485
{
481
486
if (NULL == this ->_img )
482
487
{
483
- py::print (" no img " );
488
+ py::print (" [image] is empty ! " );
484
489
return *this ;
485
490
}
486
491
if (dst_w == 0 && dst_h == 0 )
@@ -547,7 +552,7 @@ maix_image &maix_image::_draw_line(int x1, int y1, int x2, int y2, std::vector<i
547
552
{
548
553
if (NULL == this ->_img )
549
554
{
550
- py::print (" no img " );
555
+ py::print (" [image] is empty ! " );
551
556
return *this ;
552
557
}
553
558
libmaix_cv_image_draw_line (this ->_img , x1, y1, x2, y2, MaixColor (color[0 ], color[1 ], color[2 ]), thickness);
@@ -558,7 +563,7 @@ maix_image &maix_image::_draw_cross(int x, int y, int c, int size, int thickness
558
563
{
559
564
if (NULL == this ->_img )
560
565
{
561
- py::print (" no img " );
566
+ py::print (" [image] is empty ! " );
562
567
return *this ;
563
568
}
564
569
image_t img = {};
@@ -574,7 +579,7 @@ maix_image &maix_image::_draw_rectangle(int x1_x, int y1_y, int x2_w, int y2_h,
574
579
{
575
580
if (NULL == this ->_img )
576
581
{
577
- py::print (" no img " );
582
+ py::print (" [image] is empty ! " );
578
583
return *this ;
579
584
}
580
585
if (is_xywh)
@@ -587,7 +592,7 @@ maix_image &maix_image::_draw_circle(int x, int y, int r, std::vector<int> color
587
592
{
588
593
if (NULL == this ->_img )
589
594
{
590
- py::print (" no img " );
595
+ py::print (" [image] is empty ! " );
591
596
return *this ;
592
597
}
593
598
libmaix_cv_image_draw_circle (this ->_img , x, y, r, MaixColor (color[0 ], color[1 ], color[2 ]), thickness);
@@ -598,7 +603,7 @@ maix_image &maix_image::_draw_ellipse(int cx, int cy, int rx, int ry, double ang
598
603
{
599
604
if (NULL == this ->_img )
600
605
{
601
- py::print (" no img " );
606
+ py::print (" [image] is empty ! " );
602
607
return *this ;
603
608
}
604
609
libmaix_cv_image_draw_ellipse (this ->_img , cx, cy, rx, ry, angle, startAngle, endAngle, MaixColor (color[0 ], color[1 ], color[2 ]), thickness);
@@ -609,7 +614,7 @@ maix_image &maix_image::_draw_string(int x, int y, std::string str, double scale
609
614
{
610
615
if (NULL == this ->_img )
611
616
{
612
- py::print (" no img " );
617
+ py::print (" [image] is empty ! " );
613
618
return *this ;
614
619
}
615
620
libmaix_cv_image_draw_string (this ->_img , x, y, str.c_str (), scale, MaixColor (color[0 ], color[1 ], color[2 ]), thickness);
@@ -620,7 +625,7 @@ maix_image &maix_image::_rotate(double angle, int adjust)
620
625
{
621
626
if (NULL == this ->_img )
622
627
{
623
- py::print (" no img " );
628
+ py::print (" [image] is empty ! " );
624
629
return *this ;
625
630
}
626
631
libmaix_image_t *tmp = NULL ;
@@ -636,7 +641,7 @@ maix_image &maix_image::_flip(int flip)
636
641
{
637
642
if (NULL == this ->_img )
638
643
{
639
- py::print (" no img " );
644
+ py::print (" [image] is empty ! " );
640
645
return *this ;
641
646
}
642
647
libmaix_cv_image_flip (this ->_img , flip);
@@ -647,7 +652,7 @@ maix_image &maix_image::_convert(std::string mode)
647
652
{
648
653
if (NULL == this ->_img )
649
654
{
650
- py::print (" no img " );
655
+ py::print (" [image] is empty ! " );
651
656
return *this ;
652
657
}
653
658
libmaix_image_t *tmp = libmaix_image_create (this ->_img ->width , this ->_img ->height , any_cast<libmaix_image_mode_t >(this ->py_to_pram [this ->get_to (mode)][0 ]), LIBMAIX_IMAGE_LAYOUT_HWC, NULL , true );
@@ -703,7 +708,7 @@ maix_image *maix_image::_draw_crop(int x, int y, int w, int h)
703
708
{
704
709
if (NULL == this ->_img )
705
710
{
706
- py::print (" no img " );
711
+ py::print (" [image] is empty ! " );
707
712
maix_image *tmp_img = new maix_image ();
708
713
return tmp_img;
709
714
}
@@ -734,7 +739,7 @@ maix_image &maix_image::_draw_image(py::object data, int x, int y, double alpha)
734
739
{
735
740
if (NULL == this ->_img )
736
741
{
737
- py::print (" no img " );
742
+ py::print (" [image] is empty ! " );
738
743
return *this ;
739
744
}
740
745
if (py_input_maix_image != this ->get_img_type (data))
@@ -765,7 +770,7 @@ maix_image &maix_image::_set_pixel(int x, int y, std::vector<int> color)
765
770
{
766
771
if (NULL == this ->_img )
767
772
{
768
- py::print (" no img " );
773
+ py::print (" [image] is empty ! " );
769
774
return *this ;
770
775
}
771
776
libmaix_image_color_t colot_tmp;
@@ -801,7 +806,7 @@ maix_image &maix_image::_hist_eq(bool adaptive, float clip_limit, maix_image &ma
801
806
{
802
807
if (NULL == this ->_img )
803
808
{
804
- py::print (" no img " );
809
+ py::print (" [image] is empty ! " );
805
810
return *this ;
806
811
}
807
812
@@ -841,7 +846,7 @@ maix_image &maix_image::_gamma_corr(float gamma, float contrast, float brightnes
841
846
{
842
847
if (NULL == this ->_img )
843
848
{
844
- py::print (" no img " );
849
+ py::print (" [image] is empty ! " );
845
850
return *this ;
846
851
}
847
852
image_t img = {};
@@ -859,7 +864,7 @@ maix_image &maix_image::_lens_corr(float strength, float zoom, float x_corr, flo
859
864
{
860
865
if (NULL == this ->_img )
861
866
{
862
- py::print (" no img " );
867
+ py::print (" [image] is empty ! " );
863
868
return *this ;
864
869
}
865
870
@@ -880,7 +885,7 @@ maix_image &maix_image::_mean(const int ksize, bool threshold, int offset, bool
880
885
{
881
886
if (NULL == this ->_img )
882
887
{
883
- py::print (" no img " );
888
+ py::print (" [image] is empty ! " );
884
889
return *this ;
885
890
}
886
891
@@ -923,7 +928,7 @@ py::list maix_image::_imlib_get_statistics(std::vector<int> roi_src, std::vector
923
928
924
929
if (NULL == this ->_img )
925
930
{
926
- py::print (" no img " );
931
+ py::print (" [image] is empty ! " );
927
932
return py::none ();
928
933
}
929
934
@@ -1066,7 +1071,7 @@ maix_image &maix_image::_imlib_rotation_corr(float x_rotation, float y_rotation,
1066
1071
{
1067
1072
if (NULL == this ->_img )
1068
1073
{
1069
- py::print (" no img " );
1074
+ py::print (" [image] is empty ! " );
1070
1075
return *this ;
1071
1076
}
1072
1077
@@ -1093,7 +1098,7 @@ maix_image &maix_image::_opencv_Canny(double threshold1, double threshold2, int
1093
1098
{
1094
1099
if (NULL == this ->_img )
1095
1100
{
1096
- py::print (" no img " );
1101
+ py::print (" [image] is empty ! " );
1097
1102
return *this ;
1098
1103
}
1099
1104
if (this ->_maix_image_type == " RGB" )
@@ -1178,9 +1183,9 @@ py::dict maix_image::_imlib_find_template(maix_image &template_src, float arg_th
1178
1183
1179
1184
maix_image *maix_image::_warp_affine (std::vector<int > points, int w, int h)
1180
1185
{
1181
- if (NULL == this ->_img && points.size () < 4 )
1186
+ if (NULL == this ->_img || points.size () < 3 )
1182
1187
{
1183
- py::print (" no img " );
1188
+ py::print (" [image] is empty ! " );
1184
1189
maix_image *tmp_img = new maix_image ();
1185
1190
return tmp_img;
1186
1191
}
0 commit comments