@@ -69,8 +69,7 @@ void cv::gpu::log(InputArray, OutputArray, Stream&) { throw_no_cuda(); }
69
69
70
70
void cv::gpu::pow (InputArray, double , OutputArray, Stream&) { throw_no_cuda (); }
71
71
72
- void cv::gpu::compare (const GpuMat&, const GpuMat&, GpuMat&, int , Stream&) { throw_no_cuda (); }
73
- void cv::gpu::compare (const GpuMat&, Scalar, GpuMat&, int , Stream&) { throw_no_cuda (); }
72
+ void cv::gpu::compare (InputArray, InputArray, OutputArray, int , Stream&) { throw_no_cuda (); }
74
73
75
74
void cv::gpu::bitwise_not (const GpuMat&, GpuMat&, const GpuMat&, Stream&) { throw_no_cuda (); }
76
75
@@ -116,11 +115,11 @@ void cv::gpu::polarToCart(const GpuMat&, const GpuMat&, GpuMat&, GpuMat&, bool,
116
115
117
116
namespace
118
117
{
119
- typedef void (*mat_mat_func_t )(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream);
120
- typedef void (*mat_scalar_func_t )(const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream);
118
+ typedef void (*mat_mat_func_t )(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int op );
119
+ typedef void (*mat_scalar_func_t )(const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double scale, Stream& stream, int op );
121
120
122
121
void arithm_op (InputArray _src1, InputArray _src2, OutputArray _dst, InputArray _mask, double scale, int dtype, Stream& stream,
123
- mat_mat_func_t mat_mat_func, mat_scalar_func_t mat_scalar_func)
122
+ mat_mat_func_t mat_mat_func, mat_scalar_func_t mat_scalar_func, int op = 0 )
124
123
{
125
124
const int kind1 = _src1.kind ();
126
125
const int kind2 = _src2.kind ();
@@ -175,11 +174,11 @@ namespace
175
174
GpuMat dst = _dst.getGpuMat ();
176
175
177
176
if (isScalar1)
178
- mat_scalar_func (src2, val, true , dst, mask, scale, stream);
177
+ mat_scalar_func (src2, val, true , dst, mask, scale, stream, op );
179
178
else if (isScalar2)
180
- mat_scalar_func (src1, val, false , dst, mask, scale, stream);
179
+ mat_scalar_func (src1, val, false , dst, mask, scale, stream, op );
181
180
else
182
- mat_mat_func (src1, src2, dst, mask, scale, stream);
181
+ mat_mat_func (src1, src2, dst, mask, scale, stream, op );
183
182
}
184
183
}
185
184
@@ -369,7 +368,7 @@ namespace arithm
369
368
void addMat (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
370
369
}
371
370
372
- static void addMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double , Stream& _stream)
371
+ static void addMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double , Stream& _stream, int )
373
372
{
374
373
typedef void (*func_t )(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
375
374
static const func_t funcs[7 ][7 ] =
@@ -498,7 +497,7 @@ namespace arithm
498
497
void addScalar (PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
499
498
}
500
499
501
- static void addScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat& mask, double , Stream& _stream)
500
+ static void addScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat& mask, double , Stream& _stream, int )
502
501
{
503
502
typedef void (*func_t )(PtrStepSzb src1, double val, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
504
503
static const func_t funcs[7 ][7 ] =
@@ -620,7 +619,7 @@ namespace arithm
620
619
void subMat (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
621
620
}
622
621
623
- static void subMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double , Stream& _stream)
622
+ static void subMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, double , Stream& _stream, int )
624
623
{
625
624
typedef void (*func_t )(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
626
625
static const func_t funcs[7 ][7 ] =
@@ -749,7 +748,7 @@ namespace arithm
749
748
void subScalar (PtrStepSzb src1, double val, bool inv, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
750
749
}
751
750
752
- static void subScalar (const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double , Stream& _stream)
751
+ static void subScalar (const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat& mask, double , Stream& _stream, int )
753
752
{
754
753
typedef void (*func_t )(PtrStepSzb src1, double val, bool inv, PtrStepSzb dst, PtrStepb mask, cudaStream_t stream);
755
754
static const func_t funcs[7 ][7 ] =
@@ -872,7 +871,7 @@ namespace arithm
872
871
void mulMat (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream);
873
872
}
874
873
875
- static void mulMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& _stream)
874
+ static void mulMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& _stream, int )
876
875
{
877
876
typedef void (*func_t )(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream);
878
877
static const func_t funcs[7 ][7 ] =
@@ -966,7 +965,7 @@ namespace arithm
966
965
void mulScalar (PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream);
967
966
}
968
967
969
- static void mulScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat&, double scale, Stream& _stream)
968
+ static void mulScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat&, double scale, Stream& _stream, int )
970
969
{
971
970
typedef void (*func_t )(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream);
972
971
static const func_t funcs[7 ][7 ] =
@@ -1121,7 +1120,7 @@ namespace arithm
1121
1120
void divMat (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream);
1122
1121
}
1123
1122
1124
- static void divMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& _stream)
1123
+ static void divMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double scale, Stream& _stream, int )
1125
1124
{
1126
1125
typedef void (*func_t )(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, double scale, cudaStream_t stream);
1127
1126
static const func_t funcs[7 ][7 ] =
@@ -1215,7 +1214,7 @@ namespace arithm
1215
1214
void divScalar (PtrStepSzb src1, double val, bool inv, PtrStepSzb dst, cudaStream_t stream);
1216
1215
}
1217
1216
1218
- static void divScalar (const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat&, double scale, Stream& _stream)
1217
+ static void divScalar (const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat&, double scale, Stream& _stream, int )
1219
1218
{
1220
1219
typedef void (*func_t )(PtrStepSzb src1, double val, bool inv, PtrStepSzb dst, cudaStream_t stream);
1221
1220
static const func_t funcs[7 ][7 ] =
@@ -1379,7 +1378,7 @@ namespace arithm
1379
1378
void absDiffMat (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream);
1380
1379
}
1381
1380
1382
- static void absDiffMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double , Stream& _stream)
1381
+ static void absDiffMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double , Stream& _stream, int )
1383
1382
{
1384
1383
typedef void (*func_t )(PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream);
1385
1384
static const func_t funcs[] =
@@ -1451,7 +1450,7 @@ namespace arithm
1451
1450
void absDiffScalar (PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream);
1452
1451
}
1453
1452
1454
- static void absDiffScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat&, double , Stream& stream)
1453
+ static void absDiffScalar (const GpuMat& src, Scalar val, bool , GpuMat& dst, const GpuMat&, double , Stream& stream, int )
1455
1454
{
1456
1455
typedef void (*func_t )(PtrStepSzb src1, double val, PtrStepSzb dst, cudaStream_t stream);
1457
1456
static const func_t funcs[] =
@@ -1755,7 +1754,7 @@ namespace arithm
1755
1754
template <typename T> void cmpMatLe (PtrStepSzb src1, PtrStepSzb src2, PtrStepSzb dst, cudaStream_t stream);
1756
1755
}
1757
1756
1758
- void cv::gpu::compare (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, int cmpop, Stream& s )
1757
+ static void cmpMat (const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat&, double , Stream& _stream, int cmpop )
1759
1758
{
1760
1759
using namespace arithm ;
1761
1760
@@ -1780,19 +1779,7 @@ void cv::gpu::compare(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, int c
1780
1779
const int depth = src1.depth ();
1781
1780
const int cn = src1.channels ();
1782
1781
1783
- CV_Assert ( depth <= CV_64F );
1784
- CV_Assert ( src2.size () == src1.size () && src2.type () == src1.type () );
1785
- CV_Assert ( cmpop >= CMP_EQ && cmpop <= CMP_NE );
1786
-
1787
- if (depth == CV_64F)
1788
- {
1789
- if (!deviceSupports (NATIVE_DOUBLE))
1790
- CV_Error (cv::Error::StsUnsupportedFormat, " The device doesn't support double" );
1791
- }
1792
-
1793
- dst.create (src1.size (), CV_MAKE_TYPE (CV_8U, cn));
1794
-
1795
- cudaStream_t stream = StreamAccessor::getStream (s);
1782
+ cudaStream_t stream = StreamAccessor::getStream (_stream);
1796
1783
1797
1784
static const int codes[] =
1798
1785
{
@@ -1859,7 +1846,7 @@ namespace
1859
1846
}
1860
1847
}
1861
1848
1862
- void cv::gpu::compare (const GpuMat& src, Scalar sc, GpuMat& dst, int cmpop, Stream& stream)
1849
+ static void cmpScalar (const GpuMat& src, Scalar val, bool inv, GpuMat& dst, const GpuMat&, double , Stream& stream, int cmpop )
1863
1850
{
1864
1851
using namespace arithm ;
1865
1852
@@ -1881,24 +1868,24 @@ void cv::gpu::compare(const GpuMat& src, Scalar sc, GpuMat& dst, int cmpop, Stre
1881
1868
castScalar<unsigned char >, castScalar<signed char >, castScalar<unsigned short >, castScalar<short >, castScalar<int >, castScalar<float >, castScalar<double >
1882
1869
};
1883
1870
1884
- const int depth = src.depth ();
1885
- const int cn = src.channels ();
1886
-
1887
- CV_Assert ( depth <= CV_64F );
1888
- CV_Assert ( cn <= 4 );
1889
- CV_Assert ( cmpop >= CMP_EQ && cmpop <= CMP_NE );
1890
-
1891
- if (depth == CV_64F)
1871
+ if (inv)
1892
1872
{
1893
- if (!deviceSupports (NATIVE_DOUBLE))
1894
- CV_Error (cv::Error::StsUnsupportedFormat, " The device doesn't support double" );
1873
+ // src1 is a scalar; swap it with src2
1874
+ cmpop = cmpop == CMP_LT ? CMP_GT : cmpop == CMP_LE ? CMP_GE :
1875
+ cmpop == CMP_GE ? CMP_LE : cmpop == CMP_GT ? CMP_LT : cmpop;
1895
1876
}
1896
1877
1897
- dst.create (src.size (), CV_MAKE_TYPE (CV_8U, cn));
1878
+ const int depth = src.depth ();
1879
+ const int cn = src.channels ();
1880
+
1881
+ cast_func[depth](val);
1898
1882
1899
- cast_func[depth](sc);
1883
+ funcs[depth][cmpop](src, cn, val.val , dst, StreamAccessor::getStream (stream));
1884
+ }
1900
1885
1901
- funcs[depth][cmpop](src, cn, sc.val , dst, StreamAccessor::getStream (stream));
1886
+ void cv::gpu::compare (InputArray src1, InputArray src2, OutputArray dst, int cmpop, Stream& stream)
1887
+ {
1888
+ arithm_op (src1, src2, dst, noArray (), 1.0 , CV_8U, stream, cmpMat, cmpScalar, cmpop);
1902
1889
}
1903
1890
1904
1891
// ////////////////////////////////////////////////////////////////////////////
0 commit comments