gapi_smoke_test.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2018 Intel Corporation
  6. #include "test_precomp.hpp"
  7. namespace opencv_test
  8. {
  9. TEST(GAPI, Mat_Create_NoLink)
  10. {
  11. cv::Mat m1;
  12. cv::Mat m2 = m1;
  13. m2.create(32, 32, CV_8U);
  14. EXPECT_NE(m1.rows, m2.rows);
  15. EXPECT_NE(m1.cols, m2.cols);
  16. EXPECT_NE(m1.data, m2.data);
  17. }
  18. TEST(GAPI, Mat_Recreate)
  19. {
  20. cv::Mat m1 = cv::Mat::zeros(480, 640, CV_8U);
  21. m1.at<uchar>(0, 0) = 128;
  22. cv::Mat m2 = m1;
  23. EXPECT_EQ(m1.rows, m2.rows);
  24. EXPECT_EQ(m1.cols, m2.cols);
  25. EXPECT_EQ(m1.data, m2.data);
  26. EXPECT_EQ(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
  27. // Calling "create" with the same meta is NOOP - both m1 and m2 are the same
  28. m1.create(480, 640, CV_8U);
  29. EXPECT_EQ(m1.rows, m2.rows);
  30. EXPECT_EQ(m1.cols, m2.cols);
  31. EXPECT_EQ(m1.data, m2.data);
  32. EXPECT_EQ(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
  33. // Calling "create" on m2 with different meta doesn't update original m1
  34. // Now m1 and m2 are distinct
  35. m2.create(720, 1280, CV_8U);
  36. m2.at<uchar>(0, 0) = 64; // Initialize 0,0 element since m2 is a new buffer
  37. EXPECT_NE(m1.rows, m2.rows);
  38. EXPECT_NE(m1.cols, m2.cols);
  39. EXPECT_NE(m1.data, m2.data);
  40. EXPECT_NE(m1.at<uchar>(0, 0), m2.at<uchar>(0, 0));
  41. // What if a Mat is created from handle?
  42. uchar data[] = {
  43. 32, 0, 0,
  44. 0, 0, 0,
  45. 0, 0, 0
  46. };
  47. cv::Mat m3(3, 3, CV_8U, data);
  48. cv::Mat m4 = m3;
  49. EXPECT_EQ(m3.rows, m4.rows);
  50. EXPECT_EQ(m3.cols, m4.cols);
  51. EXPECT_EQ(m3.data, m4.data);
  52. EXPECT_EQ(data, m3.data);
  53. EXPECT_EQ(data, m4.data);
  54. EXPECT_EQ(m3.at<uchar>(0, 0), m4.at<uchar>(0, 0));
  55. // cv::Mat::create must be NOOP if we don't change the meta,
  56. // even if the original mat is created from handle.
  57. m4.create(3, 3, CV_8U);
  58. EXPECT_EQ(m3.rows, m4.rows);
  59. EXPECT_EQ(m3.cols, m4.cols);
  60. EXPECT_EQ(m3.data, m4.data);
  61. EXPECT_EQ(data, m3.data);
  62. EXPECT_EQ(data, m4.data);
  63. EXPECT_EQ(m3.at<uchar>(0, 0), m4.at<uchar>(0, 0));
  64. }
  65. TEST(GAPI, EmptyOutMat)
  66. {
  67. cv::Mat in_mat = cv::Mat(480, 640, CV_8U, cv::Scalar(64));
  68. cv::GComputation cc([]()
  69. {
  70. cv::GMat in;
  71. cv::GMat out = in + in;
  72. return cv::GComputation(in, out);
  73. });
  74. cv::Mat out;
  75. cc.apply(in_mat, out);
  76. EXPECT_EQ(640, out.cols);
  77. EXPECT_EQ(480, out.rows);
  78. EXPECT_EQ(CV_8U, out.type());
  79. EXPECT_EQ(0, cvtest::norm(out, (in_mat+in_mat), NORM_INF));
  80. }
  81. }