Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Euclidean Distance between Matrix Channels

I am working on background subtraction in OpenCV Android/Java. I need to find the Euclidean distance between two RGB images. First, I subtract the two images from each other, element-by-element.

Then I use this function:

private Mat euclidChannels(Mat in){
    Core.pow(in, 2, in);
    int rows = in.rows();
    Mat out = new Mat(new Size(in.cols(), in.rows()), CvType.CV_32F);
    Core.reduce(in.reshape(1,in.rows() * in.cols()), out, 1, Core.REDUCE_SUM);
    Core.sqrt(out.reshape(1, rows), out);
    return out;
}

based on the following technique: how to sum a 3 channel matrix to a one channel matrix?

I get the error:

11-06 22:45:02.094: E/cv::error()(10655): OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output array formats) in void cv::reduce(cv::InputArray, cv::OutputArray, int, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 2365

So I chased it down in the c++ source:

1921            if(op == CV_REDUCE_SUM)
1922            {
1923                if(sdepth == CV_8U && ddepth == CV_32S)
1924                    func = reduceC_<uchar,int,OpAdd<int> >;
1925                if(sdepth == CV_8U && ddepth == CV_32F)
1926                    func = reduceC_<uchar,float,OpAdd<int> >;
1927                if(sdepth == CV_8U && ddepth == CV_64F)
1928                    func = reduceC_<uchar,double,OpAdd<int> >;
1929                if(sdepth == CV_16U && ddepth == CV_32F)
1930                    func = reduceC_<ushort,float,OpAdd<float> >;
1931                if(sdepth == CV_16U && ddepth == CV_64F)
1932                    func = reduceC_<ushort,double,OpAdd<double> >;
1933                if(sdepth == CV_16S && ddepth == CV_32F)
1934                    func = reduceC_<short,float,OpAdd<float> >;
1935                if(sdepth == CV_16S && ddepth == CV_64F)
1936                    func = reduceC_<short,double,OpAdd<double> >;
1937                if(sdepth == CV_32F && ddepth == CV_32F)
1938                    func = reduceC_<float,float,OpAdd<float> >;
1939                if(sdepth == CV_32F && ddepth == CV_64F)
1940                    func = reduceC_<float,double,OpAdd<double> >;
1941                if(sdepth == CV_64F && ddepth == CV_64F)
1942                    func = reduceC_<double,double,OpAdd<double> >;
1943            }
...
1964        if( !func )
1965            CV_Error( CV_StsUnsupportedFormat,
1966            "Unsupported combination of input and output array formats" );

I think this means that none of those if statements are hitting. But, I dumped the depths of the source and destination matrices and I get 0 & 5 respectively, which should correspond to CV_8U & CV_32F (checks out in both Java and C++ source code) - and hit on line 1925 of the source.

Any ideas as to what I'm doing wrong?

(I know my listing line numbers don't match the line numbers in the error message, but the listing is all I could find on the web: matrix.cpp

click to hide/show revision 2
retagged

updated 2014-11-07 00:42:31 -0600

berak gravatar image

Euclidean Distance between Matrix Channels

I am working on background subtraction in OpenCV Android/Java. I need to find the Euclidean distance between two RGB images. First, I subtract the two images from each other, element-by-element.

Then I use this function:

private Mat euclidChannels(Mat in){
    Core.pow(in, 2, in);
    int rows = in.rows();
    Mat out = new Mat(new Size(in.cols(), in.rows()), CvType.CV_32F);
    Core.reduce(in.reshape(1,in.rows() * in.cols()), out, 1, Core.REDUCE_SUM);
    Core.sqrt(out.reshape(1, rows), out);
    return out;
}

based on the following technique: how to sum a 3 channel matrix to a one channel matrix?

I get the error:

11-06 22:45:02.094: E/cv::error()(10655): OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output array formats) in void cv::reduce(cv::InputArray, cv::OutputArray, int, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 2365

So I chased it down in the c++ source:

1921            if(op == CV_REDUCE_SUM)
1922            {
1923                if(sdepth == CV_8U && ddepth == CV_32S)
1924                    func = reduceC_<uchar,int,OpAdd<int> >;
1925                if(sdepth == CV_8U && ddepth == CV_32F)
1926                    func = reduceC_<uchar,float,OpAdd<int> >;
1927                if(sdepth == CV_8U && ddepth == CV_64F)
1928                    func = reduceC_<uchar,double,OpAdd<int> >;
1929                if(sdepth == CV_16U && ddepth == CV_32F)
1930                    func = reduceC_<ushort,float,OpAdd<float> >;
1931                if(sdepth == CV_16U && ddepth == CV_64F)
1932                    func = reduceC_<ushort,double,OpAdd<double> >;
1933                if(sdepth == CV_16S && ddepth == CV_32F)
1934                    func = reduceC_<short,float,OpAdd<float> >;
1935                if(sdepth == CV_16S && ddepth == CV_64F)
1936                    func = reduceC_<short,double,OpAdd<double> >;
1937                if(sdepth == CV_32F && ddepth == CV_32F)
1938                    func = reduceC_<float,float,OpAdd<float> >;
1939                if(sdepth == CV_32F && ddepth == CV_64F)
1940                    func = reduceC_<float,double,OpAdd<double> >;
1941                if(sdepth == CV_64F && ddepth == CV_64F)
1942                    func = reduceC_<double,double,OpAdd<double> >;
1943            }
...
1964        if( !func )
1965            CV_Error( CV_StsUnsupportedFormat,
1966            "Unsupported combination of input and output array formats" );

I think this means that none of those if statements are hitting. But, I dumped the depths of the source and destination matrices and I get 0 & 5 respectively, which should correspond to CV_8U & CV_32F (checks out in both Java and C++ source code) - and hit on line 1925 of the source.

Any ideas as to what I'm doing wrong?

(I know my listing line numbers don't match the line numbers in the error message, but the listing is all I could find on the web: matrix.cpp

click to hide/show revision 3
retagged

updated 2014-11-07 00:42:40 -0600

berak gravatar image

Euclidean Distance between Matrix Channels

I am working on background subtraction in OpenCV Android/Java. I need to find the Euclidean distance between two RGB images. First, I subtract the two images from each other, element-by-element.

Then I use this function:

private Mat euclidChannels(Mat in){
    Core.pow(in, 2, in);
    int rows = in.rows();
    Mat out = new Mat(new Size(in.cols(), in.rows()), CvType.CV_32F);
    Core.reduce(in.reshape(1,in.rows() * in.cols()), out, 1, Core.REDUCE_SUM);
    Core.sqrt(out.reshape(1, rows), out);
    return out;
}

based on the following technique: how to sum a 3 channel matrix to a one channel matrix?

I get the error:

11-06 22:45:02.094: E/cv::error()(10655): OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output array formats) in void cv::reduce(cv::InputArray, cv::OutputArray, int, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 2365

So I chased it down in the c++ source:

1921            if(op == CV_REDUCE_SUM)
1922            {
1923                if(sdepth == CV_8U && ddepth == CV_32S)
1924                    func = reduceC_<uchar,int,OpAdd<int> >;
1925                if(sdepth == CV_8U && ddepth == CV_32F)
1926                    func = reduceC_<uchar,float,OpAdd<int> >;
1927                if(sdepth == CV_8U && ddepth == CV_64F)
1928                    func = reduceC_<uchar,double,OpAdd<int> >;
1929                if(sdepth == CV_16U && ddepth == CV_32F)
1930                    func = reduceC_<ushort,float,OpAdd<float> >;
1931                if(sdepth == CV_16U && ddepth == CV_64F)
1932                    func = reduceC_<ushort,double,OpAdd<double> >;
1933                if(sdepth == CV_16S && ddepth == CV_32F)
1934                    func = reduceC_<short,float,OpAdd<float> >;
1935                if(sdepth == CV_16S && ddepth == CV_64F)
1936                    func = reduceC_<short,double,OpAdd<double> >;
1937                if(sdepth == CV_32F && ddepth == CV_32F)
1938                    func = reduceC_<float,float,OpAdd<float> >;
1939                if(sdepth == CV_32F && ddepth == CV_64F)
1940                    func = reduceC_<float,double,OpAdd<double> >;
1941                if(sdepth == CV_64F && ddepth == CV_64F)
1942                    func = reduceC_<double,double,OpAdd<double> >;
1943            }
...
1964        if( !func )
1965            CV_Error( CV_StsUnsupportedFormat,
1966            "Unsupported combination of input and output array formats" );

I think this means that none of those if statements are hitting. But, I dumped the depths of the source and destination matrices and I get 0 & 5 respectively, which should correspond to CV_8U & CV_32F (checks out in both Java and C++ source code) - and hit on line 1925 of the source.

Any ideas as to what I'm doing wrong?

(I know my listing line numbers don't match the line numbers in the error message, but the listing is all I could find on the web: matrix.cpp

click to hide/show revision 4
retagged

updated 2014-11-07 00:43:00 -0600

berak gravatar image

Euclidean Distance between Matrix Channels

I am working on background subtraction in OpenCV Android/Java. I need to find the Euclidean distance between two RGB images. First, I subtract the two images from each other, element-by-element.

Then I use this function:

private Mat euclidChannels(Mat in){
    Core.pow(in, 2, in);
    int rows = in.rows();
    Mat out = new Mat(new Size(in.cols(), in.rows()), CvType.CV_32F);
    Core.reduce(in.reshape(1,in.rows() * in.cols()), out, 1, Core.REDUCE_SUM);
    Core.sqrt(out.reshape(1, rows), out);
    return out;
}

based on the following technique: how to sum a 3 channel matrix to a one channel matrix?

I get the error:

11-06 22:45:02.094: E/cv::error()(10655): OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output array formats) in void cv::reduce(cv::InputArray, cv::OutputArray, int, int, int), file /home/reports/ci/slave_desktop/50-SDK/opencv/modules/core/src/matrix.cpp, line 2365

So I chased it down in the c++ source:

1921            if(op == CV_REDUCE_SUM)
1922            {
1923                if(sdepth == CV_8U && ddepth == CV_32S)
1924                    func = reduceC_<uchar,int,OpAdd<int> >;
1925                if(sdepth == CV_8U && ddepth == CV_32F)
1926                    func = reduceC_<uchar,float,OpAdd<int> >;
1927                if(sdepth == CV_8U && ddepth == CV_64F)
1928                    func = reduceC_<uchar,double,OpAdd<int> >;
1929                if(sdepth == CV_16U && ddepth == CV_32F)
1930                    func = reduceC_<ushort,float,OpAdd<float> >;
1931                if(sdepth == CV_16U && ddepth == CV_64F)
1932                    func = reduceC_<ushort,double,OpAdd<double> >;
1933                if(sdepth == CV_16S && ddepth == CV_32F)
1934                    func = reduceC_<short,float,OpAdd<float> >;
1935                if(sdepth == CV_16S && ddepth == CV_64F)
1936                    func = reduceC_<short,double,OpAdd<double> >;
1937                if(sdepth == CV_32F && ddepth == CV_32F)
1938                    func = reduceC_<float,float,OpAdd<float> >;
1939                if(sdepth == CV_32F && ddepth == CV_64F)
1940                    func = reduceC_<float,double,OpAdd<double> >;
1941                if(sdepth == CV_64F && ddepth == CV_64F)
1942                    func = reduceC_<double,double,OpAdd<double> >;
1943            }
...
1964        if( !func )
1965            CV_Error( CV_StsUnsupportedFormat,
1966            "Unsupported combination of input and output array formats" );

I think this means that none of those if statements are hitting. But, I dumped the depths of the source and destination matrices and I get 0 & 5 respectively, which should correspond to CV_8U & CV_32F (checks out in both Java and C++ source code) - and hit on line 1925 of the source.

Any ideas as to what I'm doing wrong?

(I know my listing line numbers don't match the line numbers in the error message, but the listing is all I could find on the web: matrix.cpp