|
|
|
@ -4,14 +4,17 @@ |
|
|
|
|
using namespace cv; |
|
|
|
|
using namespace std; |
|
|
|
|
|
|
|
|
|
#define CORE_COUNTNONZERO_ERROR_COUNT 1 |
|
|
|
|
|
|
|
|
|
#define MESSAGE_ERROR_COUNT "Count non zero elements returned by OpenCV function is incorrect." |
|
|
|
|
|
|
|
|
|
#define sign(a) a > 0 ? 1 : a == 0 ? 0 : -1 |
|
|
|
|
|
|
|
|
|
const int FLOAT_TYPE [2] = {CV_32F, CV_64F}; |
|
|
|
|
const int INT_TYPE [5] = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32S}; |
|
|
|
|
|
|
|
|
|
#define MAX_CHANNELS 4 |
|
|
|
|
#define MAX_WIDTH 1e+2 |
|
|
|
|
#define MAX_HEIGHT 1e+2 |
|
|
|
|
#define MAX_WIDTH 100 |
|
|
|
|
#define MAX_HEIGHT 100 |
|
|
|
|
|
|
|
|
|
class CV_CountNonZeroTest: public cvtest::BaseTest |
|
|
|
|
{ |
|
|
|
@ -23,360 +26,193 @@ class CV_CountNonZeroTest: public cvtest::BaseTest |
|
|
|
|
void run (int); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
float eps_32; double eps_64; Mat src; |
|
|
|
|
float eps_32;
|
|
|
|
|
double eps_64;
|
|
|
|
|
Mat src; |
|
|
|
|
int current_type; |
|
|
|
|
|
|
|
|
|
void generate_src_data(cv::Size size, int type, int channels); |
|
|
|
|
void generate_src_data(cv::Size size, int type, int channels, int count_non_zero); |
|
|
|
|
void generate_src_float_data(cv::Size size, int type, int channels, int distribution); |
|
|
|
|
void generate_src_data(cv::Size size, int type); |
|
|
|
|
void generate_src_data(cv::Size size, int type, int count_non_zero); |
|
|
|
|
void generate_src_stat_data(cv::Size size, int type, int distribution); |
|
|
|
|
|
|
|
|
|
int get_count_non_zero(); |
|
|
|
|
|
|
|
|
|
void checking_function_work();
|
|
|
|
|
void checking_function_work(int count_non_zero);
|
|
|
|
|
void print_information(int right, int result); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(1e-2), eps_64(1e-4), src(Mat()) {} |
|
|
|
|
CV_CountNonZeroTest::CV_CountNonZeroTest(): eps_32(1e-8), eps_64(1e-16), src(Mat()), current_type(-1) {} |
|
|
|
|
CV_CountNonZeroTest::~CV_CountNonZeroTest() {} |
|
|
|
|
|
|
|
|
|
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int channels) |
|
|
|
|
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type) |
|
|
|
|
{ |
|
|
|
|
src.create(size, CV_MAKETYPE(type, channels)); |
|
|
|
|
src.create(size, CV_MAKETYPE(type, 1)); |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size.width; ++i) |
|
|
|
|
for (size_t j = 0; j < size.height; ++j) |
|
|
|
|
for (size_t j = 0; j < size.width; ++j) |
|
|
|
|
for (size_t i = 0; i < size.height; ++i) |
|
|
|
|
switch (type) |
|
|
|
|
{ |
|
|
|
|
if (type == CV_8U) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<uchar>(j, i) = cv::randu<uchar>(); break;} |
|
|
|
|
case 2: {src.at<Vec2b>(j, i) = Vec2b(cv::randu<uchar>(), cv::randu<uchar>()); break;} |
|
|
|
|
case 3: {src.at<Vec3b>(j, i) = Vec3b(cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>()); break;} |
|
|
|
|
case 4: {src.at<Vec4b>(j, i) = Vec4b(cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>()); break;} |
|
|
|
|
|
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_8S) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<char>(j,i) = cv::randu<uchar>()-128; break; } |
|
|
|
|
case 2: {src.at< Vec<char, 2> >(j, i) = Vec<char, 2>(cv::randu<uchar>()-128, cv::randu<uchar>()-128); break;} |
|
|
|
|
case 3: {src.at< Vec<char, 3> >(j, i) = Vec<char, 3>(cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128); break;} |
|
|
|
|
case 4: {src.at< Vec<char, 4> >(j, i) = Vec<char, 4>(cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128); break;} |
|
|
|
|
default:break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_16U) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<ushort>(j, i) = cv::randu<ushort>(); break;} |
|
|
|
|
case 2: {src.at< Vec<ushort, 2> >(j, i) = Vec<ushort, 2>(cv::randu<ushort>(), cv::randu<ushort>()); break;} |
|
|
|
|
case 3: {src.at< Vec<ushort, 3> >(j, i) = Vec<ushort, 3>(cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>()); break;} |
|
|
|
|
case 4: {src.at< Vec<ushort, 4> >(j, i) = Vec<ushort, 4>(cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>()); break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_16S) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<short>(j, i) = cv::randu<short>(); break;} |
|
|
|
|
case 2: {src.at<Vec2s>(j, i) = Vec2s(cv::randu<short>(), cv::randu<short>()); break;} |
|
|
|
|
case 3: {src.at<Vec3s>(j, i) = Vec3s(cv::randu<short>(), cv::randu<short>(), cv::randu<short>()); break;} |
|
|
|
|
case 4: {src.at<Vec4s>(j, i) = Vec4s(cv::randu<short>(), cv::randu<short>(), cv::randu<short>(), cv::randu<short>()); break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_32S) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<int>(j, i) = cv::randu<int>(); break;} |
|
|
|
|
case 2: {src.at<Vec2i>(j, i) = Vec2i(cv::randu<int>(), cv::randu<int>()); break;} |
|
|
|
|
case 3: {src.at<Vec3i>(j, i) = Vec3i(cv::randu<int>(), cv::randu<int>(), cv::randu<int>()); break;} |
|
|
|
|
case 4: {src.at<Vec4i>(j, i) = Vec4i(cv::randu<int>(), cv::randu<int>(), cv::randu<int>(), cv::randu<int>()); break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_32F) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<float>(j, i) = cv::randu<float>(); break;} |
|
|
|
|
case 2: {src.at<Vec2f>(j, i) = Vec2i(cv::randu<float>(), cv::randu<float>()); break;} |
|
|
|
|
case 3: {src.at<Vec3f>(j, i) = Vec3i(cv::randu<float>(), cv::randu<float>(), cv::randu<float>()); break;} |
|
|
|
|
case 4: {src.at<Vec4f>(j, i) = Vec4i(cv::randu<float>(), cv::randu<float>(), cv::randu<float>(), cv::randu<float>()); break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (type == CV_64F) switch (channels) |
|
|
|
|
{ |
|
|
|
|
case 1: {src.at<double>(j, i) = cv::randu<double>(); break;} |
|
|
|
|
case 2: {src.at<Vec2d>(j, i) = Vec2d(cv::randu<double>(), cv::randu<double>()); break;} |
|
|
|
|
case 3: {src.at<Vec3d>(j, i) = Vec3d(cv::randu<double>(), cv::randu<double>(), cv::randu<double>()); break;} |
|
|
|
|
case 4: {src.at<Vec4d>(j, i) = Vec4d(cv::randu<double>(), cv::randu<double>(), cv::randu<double>(), cv::randu<double>()); break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
case CV_8U: { src.at<uchar>(i, j) = cv::randu<uchar>(); break; } |
|
|
|
|
case CV_8S: { src.at<char>(i, j) = cv::randu<uchar>() - 128; break; } |
|
|
|
|
case CV_16U: { src.at<ushort>(i, j) = cv::randu<ushort>(); break; } |
|
|
|
|
case CV_16S: { src.at<short>(i, j) = cv::randu<short>(); break; } |
|
|
|
|
case CV_32S: { src.at<int>(i, j) = cv::randu<int>(); break; } |
|
|
|
|
case CV_32F: { src.at<float>(i, j) = cv::randu<float>(); break; } |
|
|
|
|
case CV_64F: { src.at<double>(i, j) = cv::randu<double>(); break; } |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int channels, int count_non_zero) |
|
|
|
|
void CV_CountNonZeroTest::generate_src_data(cv::Size size, int type, int count_non_zero) |
|
|
|
|
{ |
|
|
|
|
src = Mat::zeros(size, CV_MAKETYPE(type, channels)); |
|
|
|
|
src = Mat::zeros(size, CV_MAKETYPE(type, 1)); |
|
|
|
|
|
|
|
|
|
int n = -1; |
|
|
|
|
int n = 0; RNG& rng = ts->get_rng(); |
|
|
|
|
|
|
|
|
|
while (n < count_non_zero) |
|
|
|
|
{ |
|
|
|
|
RNG& rng = ts->get_rng(); |
|
|
|
|
|
|
|
|
|
size_t i = rng.next()%size.height, j = rng.next()%size.width; |
|
|
|
|
size_t i = rng.next()%size.height, j = rng.next()%size.width; |
|
|
|
|
|
|
|
|
|
switch (type) |
|
|
|
|
{ |
|
|
|
|
case CV_8U:
|
|
|
|
|
{ |
|
|
|
|
if (channels == 1)
|
|
|
|
|
{ |
|
|
|
|
uchar value = cv::randu<uchar>(); |
|
|
|
|
if (value != 0) {src.at<uchar>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec2b value(cv::randu<uchar>(), cv::randu<uchar>()); |
|
|
|
|
if (value != Vec2b(0, 0)) {src.at<Vec2b>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec3b value(cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>()); |
|
|
|
|
if (value != Vec3b(0, 0, 0)) {src.at<Vec3b>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
Vec4b value(cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>(), cv::randu<uchar>()); |
|
|
|
|
if (value != Vec4b(0, 0, 0, 0)) {src.at<Vec4b>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case CV_8S: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1)
|
|
|
|
|
{ |
|
|
|
|
char value = cv::randu<uchar>()-128; |
|
|
|
|
if (value != 0) {src.at<char>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec<char, 2> value(cv::randu<uchar>()-128, cv::randu<uchar>()-128); |
|
|
|
|
if (value != Vec<char, 2>(0, 0)) {src.at< Vec<char, 2 > >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec<char, 3> value(cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128); |
|
|
|
|
if (value != Vec<char, 3>(0, 0, 0)) {src.at< Vec<char, 3> >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
Vec<char, 4> value(cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128, cv::randu<uchar>()-128); |
|
|
|
|
if (value != Vec<char, 4>(0, 0, 0, 0)) {src.at< Vec<char, 4> >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case CV_16U: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1)
|
|
|
|
|
{ |
|
|
|
|
ushort value = cv::randu<ushort>(); |
|
|
|
|
n += abs(sign(value)); |
|
|
|
|
src.at<ushort>(i, j) = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec<ushort, 2> value(cv::randu<ushort>(), cv::randu<ushort>()); |
|
|
|
|
if (value != Vec<ushort, 2>(0, 0)) {src.at< Vec<ushort, 2> >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec<ushort, 3> value(cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>()); |
|
|
|
|
if (value != Vec<ushort, 3>(0, 0, 0)) {src.at< Vec<ushort, 3> >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
Vec<ushort, 4> value(cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>(), cv::randu<ushort>()); |
|
|
|
|
if (value != Vec<ushort, 4>(0, 0, 0, 0)) {src.at< Vec<ushort, 4> >(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
switch (type) |
|
|
|
|
{ |
|
|
|
|
case CV_8U: { if (!src.at<uchar>(i, j)) {src.at<uchar>(i, j) = cv::randu<uchar>(); n += abs(sign(src.at<uchar>(i, j)));} break; } |
|
|
|
|
case CV_8S: { if (!src.at<char>(i, j)) {src.at<char>(i, j) = cv::randu<uchar>() - 128; n += abs(sign(src.at<char>(i, j)));} break; } |
|
|
|
|
case CV_16U: { if (!src.at<ushort>(i, j)) {src.at<ushort>(i, j) = cv::randu<ushort>(); n += abs(sign(src.at<ushort>(i, j)));} break; } |
|
|
|
|
case CV_16S: { if (!src.at<short>(i, j)) {src.at<short>(i, j) = cv::randu<short>(); n += abs(sign(src.at<short>(i, j)));} break; } |
|
|
|
|
case CV_32S: { if (!src.at<int>(i, j)) {src.at<int>(i, j) = cv::randu<int>(); n += abs(sign(src.at<int>(i, j)));} break; } |
|
|
|
|
case CV_32F: { if (fabs(src.at<float>(i, j)) <= eps_32) {src.at<float>(i, j) = cv::randu<float>(); n += sign(fabs(src.at<float>(i, j)) > eps_32);} break; } |
|
|
|
|
case CV_64F: { if (fabs(src.at<double>(i, j)) <= eps_64) {src.at<double>(i, j) = cv::randu<double>(); n += sign(fabs(src.at<double>(i, j)) > eps_64);} break; } |
|
|
|
|
|
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
void CV_CountNonZeroTest::generate_src_stat_data(cv::Size size, int type, int distribution) |
|
|
|
|
{ |
|
|
|
|
src.create(size, CV_MAKETYPE(type, 1)); |
|
|
|
|
|
|
|
|
|
case CV_16S: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1)
|
|
|
|
|
{ |
|
|
|
|
short value = cv::randu<short>(); |
|
|
|
|
n += abs(sign(value)); |
|
|
|
|
src.at<short>(i, j) = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec2s value(cv::randu<short>(), cv::randu<short>()); |
|
|
|
|
if (value != Vec2s(0, 0)) {src.at<Vec2s>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
double mean = 0.0, sigma = 1.0; |
|
|
|
|
double left = -1.0, right = 1.0; |
|
|
|
|
|
|
|
|
|
else if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec3s value(cv::randu<short>(), cv::randu<short>(), cv::randu<short>()); |
|
|
|
|
if (value != Vec3s(0, 0, 0)) {src.at<Vec3s>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
RNG& rng = ts->get_rng(); |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
if (distribution == RNG::NORMAL)
|
|
|
|
|
rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma)); |
|
|
|
|
else if (distribution == RNG::UNIFORM) |
|
|
|
|
rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
Vec4s value(cv::randu<short>(), cv::randu<short>(), cv::randu<short>(), cv::randu<short>()); |
|
|
|
|
if (value != Vec4s(0, 0, 0, 0)) {src.at<Vec4s>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
int CV_CountNonZeroTest::get_count_non_zero() |
|
|
|
|
{ |
|
|
|
|
int result = 0, channels = src.channels(); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
for (size_t i = 0; i < src.rows; ++i) |
|
|
|
|
for (size_t j = 0; j < src.cols; ++j) |
|
|
|
|
|
|
|
|
|
case CV_32S: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1)
|
|
|
|
|
{ |
|
|
|
|
int value = cv::randu<int>(); |
|
|
|
|
n += abs(sign(value)); |
|
|
|
|
src.at<int>(i, j) = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec2i value(cv::randu<int>(), cv::randu<int>()); |
|
|
|
|
if (value != Vec2i(0, 0)) {src.at<Vec2i>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
if (current_type == CV_8U) result += abs(sign(src.at<uchar>(i, j))); |
|
|
|
|
|
|
|
|
|
else if (current_type == CV_8S) result += abs(sign(src.at<char>(i, j)));
|
|
|
|
|
|
|
|
|
|
else if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec3i value(cv::randu<int>(), cv::randu<int>(), cv::randu<int>()); |
|
|
|
|
if (value != Vec3i(0, 0, 0)) {src.at<Vec3i>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
else if (current_type == CV_16U) result += abs(sign(src.at<ushort>(i, j)));
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
else if (current_type == CV_16S) result += abs(sign(src.at<short>(i, j))); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
Vec4i value(cv::randu<int>(), cv::randu<int>(), cv::randu<int>(), cv::randu<int>()); |
|
|
|
|
if (value != Vec4i(0, 0, 0, 0)) {src.at<Vec4i>(i, j) = value; n++;} |
|
|
|
|
} |
|
|
|
|
else if (current_type == CV_32S) result += abs(sign(src.at<int>(i, j))); |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
else if (current_type == CV_32F) result += sign(fabs(src.at<float>(i, j)) > eps_32); |
|
|
|
|
|
|
|
|
|
else result += sign(fabs(src.at<double>(i, j)) > eps_64); |
|
|
|
|
|
|
|
|
|
case CV_32F: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1) |
|
|
|
|
{ |
|
|
|
|
float value = cv::randu<float>(); |
|
|
|
|
n += sign(fabs(value) > eps_32); |
|
|
|
|
src.at<float>(i, j) = value;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec2f value(cv::randu<float>(), cv::randu<float>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_32);
|
|
|
|
|
src.at<Vec2f>(i, j) = value;
|
|
|
|
|
} |
|
|
|
|
void CV_CountNonZeroTest::print_information(int right, int result) |
|
|
|
|
{ |
|
|
|
|
cout << endl; cout << "Checking for the work of countNonZero function..." << endl; cout << endl; |
|
|
|
|
cout << "Type of Mat: ";
|
|
|
|
|
switch (current_type) |
|
|
|
|
{ |
|
|
|
|
case 0: {cout << "CV_8U"; break;}
|
|
|
|
|
case 1: {cout << "CV_8S"; break;} |
|
|
|
|
case 2: {cout << "CV_16U"; break;} |
|
|
|
|
case 3: {cout << "CV_16S"; break;} |
|
|
|
|
case 4: {cout << "CV_32S"; break;} |
|
|
|
|
case 5: {cout << "CV_32F"; break;} |
|
|
|
|
case 6: {cout << "CV_64F"; break;} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
cout << endl; |
|
|
|
|
cout << "Number of rows: " << src.rows << " Number of cols: " << src.cols << endl; |
|
|
|
|
cout << "True count non zero elements: " << right << " Result: " << result << endl;
|
|
|
|
|
cout << endl; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
void CV_CountNonZeroTest::run(int) |
|
|
|
|
{ |
|
|
|
|
const size_t N = 1500; |
|
|
|
|
|
|
|
|
|
if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec3f value(cv::randu<float>(), cv::randu<float>(), cv::randu<float>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_32);
|
|
|
|
|
src.at<Vec3f>(i, j) = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
for (int k = 1; k <= 3; ++k) |
|
|
|
|
for (size_t i = 0; i < N; ++i) |
|
|
|
|
{ |
|
|
|
|
RNG& rng = ts->get_rng(); |
|
|
|
|
|
|
|
|
|
int w = rng.next()%MAX_WIDTH + 1, h = rng.next()%MAX_HEIGHT + 1; |
|
|
|
|
|
|
|
|
|
current_type = rng.next()%7; |
|
|
|
|
|
|
|
|
|
switch (k) |
|
|
|
|
{ |
|
|
|
|
case 1: {
|
|
|
|
|
generate_src_data(Size(w, h), current_type); |
|
|
|
|
int right = get_count_non_zero(), result = countNonZero(src); |
|
|
|
|
if (result != right) |
|
|
|
|
{ |
|
|
|
|
cout << "Number of experiment: " << i << endl; |
|
|
|
|
cout << "Method of data generation: RANDOM" << endl; |
|
|
|
|
print_information(right, result); |
|
|
|
|
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case 2: { |
|
|
|
|
int count_non_zero = rng.next()%(w*h); |
|
|
|
|
generate_src_data(Size(w, h), current_type, count_non_zero); |
|
|
|
|
int result = countNonZero(src); |
|
|
|
|
if (result != count_non_zero) |
|
|
|
|
{ |
|
|
|
|
Vec4f value(cv::randu<float>(), cv::randu<float>(), cv::randu<float>(), cv::randu<float>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_32); |
|
|
|
|
src.at<Vec4f>(i, j) = value; |
|
|
|
|
cout << "Number of experiment: " << i << endl; |
|
|
|
|
cout << "Method of data generation: HALF-RANDOM" << endl; |
|
|
|
|
print_information(count_non_zero, result); |
|
|
|
|
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case CV_64F: |
|
|
|
|
{ |
|
|
|
|
if (channels == 1) |
|
|
|
|
{ |
|
|
|
|
double value = cv::randu<double>(); |
|
|
|
|
n += sign(fabs(value) > eps_64); |
|
|
|
|
src.at<double>(i, j) = value;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
if (channels == 2) |
|
|
|
|
{ |
|
|
|
|
Vec2d value(cv::randu<double>(), cv::randu<double>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_64);
|
|
|
|
|
src.at<Vec2d>(i, j) = value;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (channels == 3) |
|
|
|
|
{ |
|
|
|
|
Vec3d value(cv::randu<double>(), cv::randu<double>(), cv::randu<double>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_64);
|
|
|
|
|
src.at<Vec3d>(i, j) = value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
|
|
case 3: { |
|
|
|
|
int distribution = cv::randu<uchar>()%2; |
|
|
|
|
generate_src_stat_data(Size(w, h), current_type, distribution); |
|
|
|
|
int right = get_count_non_zero(), result = countNonZero(src); |
|
|
|
|
if (right != result) |
|
|
|
|
{ |
|
|
|
|
Vec4d value(cv::randu<double>(), cv::randu<double>(), cv::randu<double>(), cv::randu<double>()); |
|
|
|
|
n += sign(cv::norm(value) > eps_64); |
|
|
|
|
src.at<Vec4d>(i, j) = value; |
|
|
|
|
cout << "Number of experiment: " << i << endl; |
|
|
|
|
cout << "Method of data generation: STATISTIC" << endl; |
|
|
|
|
print_information(right, result); |
|
|
|
|
CV_Error(CORE_COUNTNONZERO_ERROR_COUNT, MESSAGE_ERROR_COUNT); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
default: break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CV_CountNonZeroTest::generate_src_float_data(cv::Size size, int type, int channels, int distribution) |
|
|
|
|
{ |
|
|
|
|
src.create(size, CV_MAKETYPE(type, channels)); |
|
|
|
|
|
|
|
|
|
double mean = 0.0, sigma = 1.0; |
|
|
|
|
double left = -1.0, right = 1.0; |
|
|
|
|
|
|
|
|
|
RNG& rng = ts->get_rng(); |
|
|
|
|
|
|
|
|
|
if (distribution == RNG::NORMAL)
|
|
|
|
|
rng.fill(src, RNG::NORMAL, Scalar::all(mean), Scalar::all(sigma)); |
|
|
|
|
else if (distribution == RNG::UNIFORM) |
|
|
|
|
rng.fill(src, RNG::UNIFORM, Scalar::all(left), Scalar::all(right)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CV_CountNonZeroTest::run(int) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); } |
|
|
|
|
// TEST (Core_CountNonZero, accuracy) { CV_CountNonZeroTest test; test.safe_run(); }
|