Commit 732bd621 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

added masks support for bitwise operations on GPU

parent 3163cfb8
...@@ -474,53 +474,53 @@ namespace cv ...@@ -474,53 +474,53 @@ namespace cv
//! computes magnitude of each (x(i), y(i)) vector //! computes magnitude of each (x(i), y(i)) vector
//! supports only floating-point source //! supports only floating-point source
CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude); CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
//! Async version //! async version
CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream); CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
//! computes squared magnitude of each (x(i), y(i)) vector //! computes squared magnitude of each (x(i), y(i)) vector
//! supports only floating-point source //! supports only floating-point source
CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude); CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
//! Async version //! async version
CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream); CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
//! computes angle (angle(i)) of each (x(i), y(i)) vector //! computes angle (angle(i)) of each (x(i), y(i)) vector
//! supports only floating-point source //! supports only floating-point source
CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false); CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false);
//! Async version //! async version
CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream); CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream);
//! converts Cartesian coordinates to polar //! converts Cartesian coordinates to polar
//! supports only floating-point source //! supports only floating-point source
CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false); CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false);
//! Async version //! async version
CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees, const Stream& stream); CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees, const Stream& stream);
//! converts polar coordinates to Cartesian //! converts polar coordinates to Cartesian
//! supports only floating-point source //! supports only floating-point source
CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false); CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false);
//! Async version //! async version
CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, const Stream& stream); CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, const Stream& stream);
//! Perfroms per-elements bit-wise inversion //! perfroms per-elements bit-wise inversion
CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst); CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat());
//! Async version //! async version
CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const Stream& stream); CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask, const Stream& stream);
//! Calculates per-element bit-wise disjunction of two arrays //! calculates per-element bit-wise disjunction of two arrays
CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst); CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
//! Async version //! async version
CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream); CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
//! Calculates per-element bit-wise conjunction of two arrays //! calculates per-element bit-wise conjunction of two arrays
CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst); CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
//! Async version //! async version
CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream); CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
//! Calculates per-element bit-wise "exclusive or" operation //! calculates per-element bit-wise "exclusive or" operation
CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst); CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
//! Async version //! async version
CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream); CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
//! Logical operators //! Logical operators
CV_EXPORTS GpuMat operator ~ (const GpuMat& src); CV_EXPORTS GpuMat operator ~ (const GpuMat& src);
...@@ -551,7 +551,7 @@ namespace cv ...@@ -551,7 +551,7 @@ namespace cv
//! Supported types of input disparity: CV_8U, CV_16S. //! Supported types of input disparity: CV_8U, CV_16S.
//! Output disparity has CV_8UC4 type in BGRA format (alpha = 255). //! Output disparity has CV_8UC4 type in BGRA format (alpha = 255).
CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp); CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp);
//! Async version //! async version
CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, const Stream& stream); CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, const Stream& stream);
//! Reprojects disparity image to 3D space. //! Reprojects disparity image to 3D space.
...@@ -560,12 +560,12 @@ namespace cv ...@@ -560,12 +560,12 @@ namespace cv
//! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map. //! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map.
//! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify. //! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify.
CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q); CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q);
//! Async version //! async version
CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, const Stream& stream); CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, const Stream& stream);
//! converts image from one color space to another //! converts image from one color space to another
CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0); CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0);
//! Async version //! async version
CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream); CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream);
//! applies fixed threshold to the image. //! applies fixed threshold to the image.
...@@ -821,7 +821,7 @@ namespace cv ...@@ -821,7 +821,7 @@ namespace cv
//! Output disparity has CV_8U type. //! Output disparity has CV_8U type.
void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity); void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity);
//! Async version //! async version
void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream & stream); void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream & stream);
//! Some heuristics that tries to estmate //! Some heuristics that tries to estmate
...@@ -876,7 +876,7 @@ namespace cv ...@@ -876,7 +876,7 @@ namespace cv
//! if disparity is empty output type will be CV_16S else output type will be disparity.type(). //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity); void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
//! Async version //! async version
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream); void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
...@@ -935,7 +935,7 @@ namespace cv ...@@ -935,7 +935,7 @@ namespace cv
//! if disparity is empty output type will be CV_16S else output type will be disparity.type(). //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity); void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
//! Async version //! async version
void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream); void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
int ndisp; int ndisp;
...@@ -991,7 +991,7 @@ namespace cv ...@@ -991,7 +991,7 @@ namespace cv
//! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type. //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst); void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst);
//! Async version //! async version
void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream); void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream);
private: private:
......
This diff is collapsed.
This diff is collapsed.
...@@ -60,7 +60,7 @@ struct CV_GpuBitwiseTest: public CvTest ...@@ -60,7 +60,7 @@ struct CV_GpuBitwiseTest: public CvTest
int rows, cols; int rows, cols;
for (int depth = CV_8U; depth <= CV_64F; ++depth) for (int depth = CV_8U; depth <= CV_64F; ++depth)
for (int cn = 1; cn <= 4; ++cn) for (int cn = 1; cn <= 4; ++cn)
for (int attempt = 0; attempt < 5; ++attempt) for (int attempt = 0; attempt < 3; ++attempt)
{ {
rows = 1 + rand() % 100; rows = 1 + rand() % 100;
cols = 1 + rand() % 100; cols = 1 + rand() % 100;
...@@ -83,7 +83,12 @@ struct CV_GpuBitwiseTest: public CvTest ...@@ -83,7 +83,12 @@ struct CV_GpuBitwiseTest: public CvTest
} }
Mat dst_gold = ~src; Mat dst_gold = ~src;
gpu::GpuMat dst = ~gpu::GpuMat(src);
gpu::GpuMat mask(src.size(), CV_8U);
mask.setTo(Scalar(1));
gpu::GpuMat dst;
gpu::bitwise_not(gpu::GpuMat(src), dst, mask);
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
...@@ -112,10 +117,23 @@ struct CV_GpuBitwiseTest: public CvTest ...@@ -112,10 +117,23 @@ struct CV_GpuBitwiseTest: public CvTest
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
Mat dsth(dst); Mat dsth(dst);
for (int i = 0; i < dst_gold.rows; ++i) for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT) CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
Mat mask(src1.size(), CV_8U);
randu(mask, Scalar(0), Scalar(255));
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
bitwise_or(src1, src2, dst_gold2, mask);
gpu::bitwise_or(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
dsth = dst2;
for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
} }
void test_bitwise_and(int rows, int cols, int type) void test_bitwise_and(int rows, int cols, int type)
...@@ -138,10 +156,24 @@ struct CV_GpuBitwiseTest: public CvTest ...@@ -138,10 +156,24 @@ struct CV_GpuBitwiseTest: public CvTest
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
Mat dsth(dst); Mat dsth(dst);
for (int i = 0; i < dst_gold.rows; ++i) for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT) CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
Mat mask(src1.size(), CV_8U);
randu(mask, Scalar(0), Scalar(255));
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
bitwise_and(src1, src2, dst_gold2, mask);
gpu::bitwise_and(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
dsth = dst2;
for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
} }
void test_bitwise_xor(int rows, int cols, int type) void test_bitwise_xor(int rows, int cols, int type)
...@@ -164,10 +196,24 @@ struct CV_GpuBitwiseTest: public CvTest ...@@ -164,10 +196,24 @@ struct CV_GpuBitwiseTest: public CvTest
CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.size() == dst.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT); CHECK(dst_gold.type() == dst.type(), CvTS::FAIL_INVALID_OUTPUT);
Mat dsth(dst); Mat dsth(dst);
for (int i = 0; i < dst_gold.rows; ++i) for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT) CHECK(memcmp(dst_gold.ptr(i), dsth.ptr(i), dst_gold.cols * dst_gold.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
Mat mask(src1.size(), CV_8U);
randu(mask, Scalar(0), Scalar(255));
Mat dst_gold2(dst_gold.size(), dst_gold.type()); dst_gold2.setTo(Scalar::all(0));
gpu::GpuMat dst2(dst.size(), dst.type()); dst2.setTo(Scalar::all(0));
bitwise_xor(src1, src2, dst_gold2, mask);
gpu::bitwise_xor(gpu::GpuMat(src1), gpu::GpuMat(src2), dst2, gpu::GpuMat(mask));
CHECK(dst_gold2.size() == dst2.size(), CvTS::FAIL_INVALID_OUTPUT);
CHECK(dst_gold2.type() == dst2.type(), CvTS::FAIL_INVALID_OUTPUT);
dsth = dst2;
for (int i = 0; i < dst_gold.rows; ++i)
CHECK(memcmp(dst_gold2.ptr(i), dsth.ptr(i), dst_gold2.cols * dst_gold2.elemSize()) == 0, CvTS::FAIL_INVALID_OUTPUT)
} }
} gpu_bitwise_test; } gpu_bitwise_test;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment