Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTPATTERN.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

but the main error is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, with type 0 (unknown, or uchar)

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTPATTERN.ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

but the main error is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, with type 0 (unknown, or uchar)

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

but the main error is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, with which defaults to type 0 (unknown, or uchar)
0

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

but the main error is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type 0
CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying tape again.

but the main error problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying tape type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double))double. an expectation mismatch. you should have checked the depth() before applying at()))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double. an expectation mismatch. you should have checked the depth() type() before applying at()))at(), plain guessing will ALWAYS lead to shooting your own foot))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

no, filter2D() NEVER rounds anything. what you observe are errors in your code.

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double. an expectation mismatch. you should have checked the type() before applying at(), plain guessing will ALWAYS lead to shooting your own foot))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

no, filter2D() NEVER rounds does not round anything. what you observe are errors in your code.

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

do not abuse a random access operator for whole images / ROIs

(it's also hard to get the type right (and you got it wrong, it's uchar, not double. an expectation mismatch. you should have checked the type() before applying at(), plain guessing will ALWAYS lead to shooting your own foot))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]

no, filter2D() does not round anything. what you observe are errors in your code.

please NEVER write for loops like that with opencv. it's the most dangerous and silly noob ANTIPATTERN there is.

(it's also hard to get the type right (and you got it wrong, it's uchar, not double. an expectation mismatch. you should have checked the type() before applying at(), plain guessing will ALWAYS lead to shooting your own foot))

rather print out your Mat like:

cout << ratio(Range(90,93), Range(70,75)) << endl;

and you won't have to worry about the underlying type ever, again.

but the main problem is here:

filter2D(ratioB, ratio, ratio.depth(), kernel, Point(-1, -1), 0,
                        ^
                        ratio is an *empty* (uninitialized) Mat, which defaults to type CV_8U

replacing it with :

filter2D(ratioB, ratio, CV_64F, kernel, Point(-1, -1), 0,

(and using a proper cout statement, NOT a for loop) yields the probably correct:

[1.064462175504303, 1.081087461852151, 1.093795521963379, 1.103062688483393, 1.109410216302785;
 1.096379468908243, 1.113049809562855, 1.125585710677836, 1.1345460270182, 1.140489215023692;
 1.120826367398934, 1.137233223043043, 1.149376122330102, 1.157815148607972, 1.163169752913307]