cv::compare's output does not match documentation (Bug #3149)


Added by M. H. over 11 years ago. Updated over 11 years ago.


Status:Done Start date:2013-07-10
Priority:Normal Due date:
Assignee:M. H. % Done:

100%

Category:documentation
Target version:2.4.7
Affected version:2.4.6 (latest release) Operating System:Any
Difficulty: HW Platform:Any
Pull request:

Description

Commit d8417af0860 ([1], July 2011) changed cv::compare to operate on n-channel matrices. The function's destination is now also n-channel. The documentation2 was not updated accordingly and still describes the result to be CV_8UC1. Getting a single-channel output is useful: it can be fed into cv::countNonZero to determine whether two matrices are exactly equal. cv::countNonZero does not work with matrices with more than one channel.

The documentation should be updated to reflect the changes made in commit d8417af0860, and there should be a way to retrieve a single-channel comparison matrix and/or cv::countNonZero should be extended to support n-channel matrices.

Example code:

const auto
  mat1 = cv::Mat::zeros(100, 50, CV_8UC4),
  mat2 = cv::Mat::ones(100, 50, CV_8UC4);

const auto tmp = cv::Mat(mat1 != mat2);

std::cout << "channels = " << tmp.channels() << std::endl;
std::cout << "nonzero = " << cv::countNonZero(mat1 != mat2) << std::endl;

Output:

channels = 4
OpenCV Error: Assertion failed (src.channels() == 1 && func != 0) in countNonZero, file /[…]/modules/core/src/stat.cpp, line 496

[1] https://github.com/Itseez/opencv/commit/d8417af0860b8c718722734e5898ddaea055699e
[2] http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#compare


Associated revisions

Revision b5d073ad
Added by Vadim Pisarevsky over 10 years ago

Merge pull request #3149 from StevenPuttemans:fix_nonfree_includes

History

Updated by Nikita Manovich over 11 years ago

Hi,

Thank you for your bug report. Could you please help us with the issue? Our own resources are very limited. Please look at http://www.code.opencv.org/projects/opencv/wiki/How_to_contribute link. If you have time please send us a pull request. We will be glad to integrate your changes.
Documentation should be updated definetely but I'm not sure about cv::countNonZero. You can always extract separate channels using cv::split and process them one by one. Does it make sense for you?

  • Assignee changed from Vadim Pisarevsky to M. H.
  • Category changed from core to documentation
  • Status changed from New to Open

Updated by M. H. over 11 years ago

The documentation was fixed in commit cdc2ee9789d26 (https://github.com/Itseez/opencv/commit/cdc2ee9789d269141378f1a8a698d3debcf49257) on the 2.4 branch.

  • % Done changed from 0 to 100
  • Target version set to 2.4.7

Updated by M. H. over 11 years ago

  • Status changed from Open to Done

Also available in: Atom PDF