[Example/custom/opencv] Backward compatibility for old opencv
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 8 Apr 2020 01:58:02 +0000 (10:58 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 8 Apr 2020 04:10:20 +0000 (13:10 +0900)
The previous commit is for OPENCV3. Keep the old code for OPENCV2 or before.

Changed in v2:
- Per the comment from Tae-Young Chung,
"opencv3 also supports this change (opencv3 support c++)
how old opencv version should be supported? for example, opencv2.x?"
The backward compatibility patch is adjusted to support 2 or before.

Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
nnstreamer_example/custom_example_opencv/nnstreamer_customfilter_opencv_scaler.cc

index 9a16efb..fb09b9c 100644 (file)
@@ -140,15 +140,28 @@ pt_allocate_invoke (void *private_data,
   /* Get Mat object from input tensor */
   memcpy (buffer, input[0].data, in_size);
   img_src = cv::Mat (pdata->in_height, pdata->in_width, CV_8UC3, buffer);
+#if CV_MAJOR_VERSION >= 3
   cv::cvtColor (img_src, img_src, cv::COLOR_BGR2RGB);
+#else
+  cv::cvtColor (img_src, img_src, CV_BGR2RGB);
+#endif
 
   /* Scale from the shape of input tensor to that of output tensor
    * which is given as custom property */
+#if CV_MAJOR_VERSION >= 3
   cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height),
             0, 0, cv::INTER_NEAREST);
+#else
+  cv::resize (img_src, img_dst, cv::Size(pdata->out_width, pdata->out_height),
+            0, 0, CV_INTER_NN);
+#endif
 
   /* Convert Mat object to output tensor */
+#if CV_MAJOR_VERSION >= 3
   cv::cvtColor (img_dst, img_dst, cv::COLOR_RGB2BGR);
+#else
+  cv::cvtColor (img_dst, img_dst, CV_RGB2BGR);
+#endif
   memcpy (output[0].data, img_dst.data, out_size);
 
   g_free(buffer);