added 16-bit support to Bayer2RGB & Bayer2Gray (ticket #686)
This commit is contained in:
parent
ce8437d37f
commit
262fc33024
@ -1528,7 +1528,7 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
CV_ColorBayerTest::CV_ColorBayerTest() : CV_ColorCvtBaseTest( false, false, false )
|
||||
CV_ColorBayerTest::CV_ColorBayerTest() : CV_ColorCvtBaseTest( false, false, true )
|
||||
{
|
||||
test_array[OUTPUT].pop_back();
|
||||
test_array[REF_OUTPUT].pop_back();
|
||||
@ -1545,8 +1545,8 @@ void CV_ColorBayerTest::get_test_array_types_and_sizes( int test_case_idx, vecto
|
||||
RNG& rng = ts->get_rng();
|
||||
CV_ColorCvtBaseTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
|
||||
|
||||
types[INPUT][0] = CV_8UC1;
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_8UC3;
|
||||
types[INPUT][0] = CV_MAT_DEPTH(types[INPUT][0]);
|
||||
types[OUTPUT][0] = types[REF_OUTPUT][0] = CV_MAKETYPE(CV_MAT_DEPTH(types[INPUT][0]), 3);
|
||||
inplace = false;
|
||||
|
||||
fwd_code = cvtest::randInt(rng)%4 + CV_BayerBG2BGR;
|
||||
@ -1571,22 +1571,20 @@ void CV_ColorBayerTest::run_func()
|
||||
}
|
||||
|
||||
|
||||
void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
template<typename T>
|
||||
static void bayer2BGR_(const Mat& src, Mat& dst, int code)
|
||||
{
|
||||
const Mat& src = test_mat[INPUT][0];
|
||||
Mat& dst = test_mat[REF_OUTPUT][0];
|
||||
int i, j, cols = src.cols - 2;
|
||||
int code = fwd_code;
|
||||
int bi = 0;
|
||||
int step = src.step;
|
||||
|
||||
if( fwd_code == CV_BayerRG2BGR || fwd_code == CV_BayerGR2BGR )
|
||||
int step = (int)(src.step/sizeof(T));
|
||||
|
||||
if( code == CV_BayerRG2BGR || code == CV_BayerGR2BGR )
|
||||
bi ^= 2;
|
||||
|
||||
|
||||
for( i = 1; i < src.rows - 1; i++ )
|
||||
{
|
||||
const uchar* ptr = src.ptr(i) + 1;
|
||||
uchar* dst_row = dst.ptr(i) + 3;
|
||||
const T* ptr = src.ptr<T>(i) + 1;
|
||||
T* dst_row = dst.ptr<T>(i) + 3;
|
||||
int save_code = code;
|
||||
if( cols <= 0 )
|
||||
{
|
||||
@ -1594,7 +1592,7 @@ void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
dst_row[cols*3] = dst_row[cols*3+1] = dst_row[cols*3+2] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for( j = 0; j < cols; j++ )
|
||||
{
|
||||
int b, g, r;
|
||||
@ -1611,9 +1609,9 @@ void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
r = (ptr[j-step] + ptr[j+step]) >> 1;
|
||||
}
|
||||
code ^= 1;
|
||||
dst_row[j*3 + bi] = (uchar)b;
|
||||
dst_row[j*3 + 1] = (uchar)g;
|
||||
dst_row[j*3 + (bi^2)] = (uchar)r;
|
||||
dst_row[j*3 + bi] = (T)b;
|
||||
dst_row[j*3 + 1] = (T)g;
|
||||
dst_row[j*3 + (bi^2)] = (T)r;
|
||||
}
|
||||
|
||||
dst_row[-3] = dst_row[0];
|
||||
@ -1629,14 +1627,14 @@ void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
|
||||
if( src.rows <= 2 )
|
||||
{
|
||||
memset( dst.ptr(), 0, (cols+2)*3 );
|
||||
memset( dst.ptr(dst.rows-1), 0, (cols+2)*3 );
|
||||
memset( dst.ptr(), 0, (cols+2)*3*sizeof(T) );
|
||||
memset( dst.ptr(dst.rows-1), 0, (cols+2)*3*sizeof(T) );
|
||||
}
|
||||
else
|
||||
{
|
||||
uchar* top_row = dst.ptr();
|
||||
uchar* bottom_row = dst.ptr(dst.rows-1);
|
||||
int dstep = dst.step;
|
||||
T* top_row = dst.ptr<T>();
|
||||
T* bottom_row = dst.ptr<T>(dst.rows-1);
|
||||
int dstep = (int)(dst.step/sizeof(T));
|
||||
|
||||
for( j = 0; j < (cols+2)*3; j++ )
|
||||
{
|
||||
@ -1646,6 +1644,20 @@ void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CV_ColorBayerTest::prepare_to_validation( int /*test_case_idx*/ )
|
||||
{
|
||||
const Mat& src = test_mat[INPUT][0];
|
||||
Mat& dst = test_mat[REF_OUTPUT][0];
|
||||
int depth = src.depth();
|
||||
if( depth == CV_8U )
|
||||
bayer2BGR_<uchar>(src, dst, fwd_code);
|
||||
else if( depth == CV_16U )
|
||||
bayer2BGR_<ushort>(src, dst, fwd_code);
|
||||
else
|
||||
CV_Error(CV_StsUnsupportedFormat, "");
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TEST(Imgproc_ColorGray, accuracy) { CV_ColorGrayTest test; test.safe_run(); }
|
||||
|
@ -1,3 +1,38 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
CV_TEST_MAIN("cv")
|
||||
|
||||
#if 0
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
#if 0
|
||||
Mat src = imread("/Users/vp/Downloads/resize/original.png"), dst;
|
||||
//resize(src, dst, Size(), 0.25, 0.25, INTER_NEAREST);
|
||||
//imwrite("/Users/vp/Downloads/resize/xnview_nn_opencv.png", dst);
|
||||
printf("\n\n\n\n\n\n***************************************\n");
|
||||
//resize(src, dst, Size(), 0.25, 0.25, INTER_AREA);
|
||||
//int nsteps = 4;
|
||||
//double rate = pow(0.25,1./nsteps);
|
||||
//for( int i = 0; i < nsteps; i++ )
|
||||
// resize(src, src, Size(), rate, rate, INTER_LINEAR );
|
||||
//GaussianBlur(src, src, Size(5, 5), 2, 2);
|
||||
resize(src, src, Size(), 0.25, 0.25, INTER_NEAREST);
|
||||
imwrite("/Users/vp/Downloads/resize/xnview_bilinear_opencv.png", src);
|
||||
//resize(src, dst, Size(), 0.25, 0.25, INTER_LANCZOS4);
|
||||
//imwrite("/Users/vp/Downloads/resize/xnview_lanczos3_opencv.png", dst);
|
||||
#else
|
||||
float data[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
Mat src(5,5,CV_32FC1, data);
|
||||
Mat dst;
|
||||
resize(src, dst, Size(), 3, 3, INTER_NEAREST);
|
||||
cout << src << endl;
|
||||
cout << dst << endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user