cvInRangeS() with different behavior between versions (Bug #1500)
Description
cvInRangeS() behavior is differ between OpenCV 2.2.0 and 2.3.0.
OS, Compiler:- Windows XP Pro SP3
- Visual Studio 2008 Standard SP1
code is this:
1#if 1 // [[OpenCV]] 2.1.0
2 #include <opencv/cv.h>
3 #include <opencv/cvver.h>
4#else // [[OpenCV]] 2.2 or later
5 #include <opencv2/core/core_c.h>
6 #include <opencv2/core/version.hpp>
7#endif
8
9#include <stdio.h>
10
11int
12main(int, char*[]) {
13 printf("CV_VERSION = %s\n", CV_VERSION);
14
15 [[CvSize]] size = cvSize(1, 5);
16 [[IplImage]]* src = cvCreateImage(size, IPL_DEPTH_8U, 1);
17 [[IplImage]]* dst = cvCreateImage(size, IPL_DEPTH_8U, 1);
18
19 // set 200 to 204
20 for (int y = 0; y < size.height; ++y) {
21 cvSet2D(src, y, 0, cvScalar(200 + y));
22 }
23
24 // inRangeS
25 cvInRangeS(src, cvScalar(201), cvScalar(203), dst);
26
27 printf("src: ");
28 for (int y = 0; y < size.height; ++y) {
29 printf("%3d ", (int)cvGet2D(src, y, 0).valr0);
30 }
31 printf("\n");
32
33 printf("dst: ");
34 for (int y = 0; y < size.height; ++y) {
35 printf("%3d ", (int)cvGet2D(dst, y, 0).valr0);
36 }
37 printf("\n");
38
39 cvReleaseImage(&dst);
40 cvReleaseImage(&src);
41
42 return 0;
43}
In versions 2.1.0/2.2.0 32bits windows it returns:
CV_VERSION = 2.1.0 src: 200 201 202 203 204 dst: 0 255 255 0 0 --- CV_VERSION = 2.2.0 src: 200 201 202 203 204 dst: 0 255 255 0 0 ---
In vaersions 2.3.0/2.3.1 32bits windows it returns:
CV_VERSION = 2.3.0 src: 200 201 202 203 204 dst: 0 255 255 255 0 === CV_VERSION = 2.3.1 src: 200 201 202 203 204 dst: 0 255 255 255 0 ===
behavoir of the cvInRangeS() of the version 2.1.0 and 2.2.0 is 'low <= value < high'
but, cvInRangeS() of the version 2.3.0 and 2.3.1 is 'low <= value <= high'. It is having changed the behavior at the following changeset:
- [changeset:4885/trunk/opencv/modules/core/src/arithm.cpp]
Best Regards,
Chihiro Hamatani
Associated revisions
fixed description of inRange/inRangeS (ticket #1500)
Merge pull request #1500 from alalek:fix_add_definitions
History
Updated by Vadim Pisarevsky over 13 years ago
thanks for the report! Indeed, the behavior has been changed to be able to handle white pixels (255) in 8u images. That is, to include 255-pixels within the range, one had to specify the upper boundary=256, which can not be represented in 8u format.
In trunk, r7041, formulas in inRange[S] have been corrected.
Sorry for the quiet change in semantics, we are trying to minimize the number of such cases.
- Status changed from Open to Done
- (deleted custom field) set to wontfix
Updated by Andrey Kamaev almost 13 years ago
- Status changed from Done to Cancelled
- Target version set to 2.4.0