File: test_common.cpp

package info (click to toggle)
opencv 4.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 276,172 kB
  • sloc: cpp: 1,079,020; xml: 682,526; python: 43,885; lisp: 30,943; java: 25,642; ansic: 7,968; javascript: 5,956; objc: 2,039; sh: 1,017; cs: 601; perl: 494; makefile: 179
file content (51 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "test_precomp.hpp"
#include "test_common.hpp"

namespace opencv_test {

static
Mat generateTestImageBGR_()
{
    Size sz(640, 480);
    Mat result(sz, CV_8UC3, Scalar::all(0));

    const string fname = cvtest::findDataFile("../cv/shared/baboon.png");
    Mat image = imread(fname, IMREAD_COLOR);
    CV_Assert(!image.empty());
    CV_CheckEQ(image.size(), Size(512, 512), "");
    Rect roi((640-512) / 2, 0, 512, 480);
    image(Rect(0, 0, 512, 480)).copyTo(result(roi));
    result(Rect(0,  0, 5, 5)).setTo(Scalar(0, 0, 255));  // R
    result(Rect(5,  0, 5, 5)).setTo(Scalar(0, 255, 0));  // G
    result(Rect(10, 0, 5, 5)).setTo(Scalar(255, 0, 0));  // B
    result(Rect(0,  5, 5, 5)).setTo(Scalar(128, 128, 128));  // gray
    //imshow("test_image", result); waitKey();
    return result;
}
Mat generateTestImageBGR()
{
    static Mat image = generateTestImageBGR_();  // initialize once
    CV_Assert(!image.empty());
    return image;
}

static
Mat generateTestImageGrayscale_()
{
    Mat imageBGR = generateTestImageBGR();
    CV_Assert(!imageBGR.empty());

    Mat result;
    cvtColor(imageBGR, result, COLOR_BGR2GRAY);
    return result;
}
Mat generateTestImageGrayscale()
{
    static Mat image = generateTestImageGrayscale_();  // initialize once
    return image;
}

}  // namespace