Fail to assign value at (y,x)

Hi, I’m trying to make a single pixel white like this:
vertical_filtered_mat.at<uint>(y, x) = 255;
And it throws these COMPILATION errors:


How can I fix this?
src code:

inline Point catch_feature( Mat img,
uint8_t threshold = 50,
uint8_t shrink_factor = 5,
uint8_t ker_dim = 3) {

// vars
int height = img.cols;
int width = img.cols;

int filtered_met_size = height - ker_dim + 1;

Mat vertical_filtered_mat = Mat::zeros(Size(filtered_met_size / shrink_factor, filtered_met_size / shrink_factor), CV_8U);
Mat horizontal_filtered_mat = Mat::zeros(Size(filtered_met_size / shrink_factor, filtered_met_size / shrink_factor), CV_8U);

// logic
// vertical seperator
for (size_t y = 1; y < height - 1; y += shrink_factor) {
	for (size_t x = 1; x < width - 2; x += shrink_factor) {
		// check if 2 places to the right is brighter
		if (img.at<uchar>(y, x + 2) - img.at<uchar>(y, x) > threshold) {
			for (int dy = -((ker_dim - 1) / 2); dy <= (ker_dim - 1) / 2; dy++) {
				for (int dx = -((ker_dim - 1) / 2); dx <= (ker_dim - 1) / 2; dx++) {
					if (img.at<uchar>(y + dy, x + dx + 2) - img.at<uchar>(y + dy, x + dx) > threshold) {
						vertical_filtered_mat.at<uint>(y, x) = 255; // ERROR HERE
					}
				}
			}
		}
	}
}

return Point(-1, -1);

}

Thanks :slight_smile:

insufficient. MRE please.

there’ s no such thing as an uint pixel format in opencv
(you probably mean uchar?)
((your Mat was allocated as CV_8U, so you must use uchar for get / set ops))
(((that said, please avoid code like above. it’s slow & error prone)))

1 Like

oh yea, that was it… awkward 0_0 … Thanks! :slight_smile:

mind challenge: try to vectorize this

e.g : don’t try to compare a single pixel to it’s neighbour , 2 pix right, but compare a whole Mat to another (slice), shifted 2 pix to the right :wink:

also, for convolution, there’s filter2D()

NEVER WRITE FOR LOOPS HERE !

1 Like

Interesting,
How heavy would it be on a system compared to the algorithm above?
This code will be embedded inside a very limited-recourse chip, so I want this to be as lightweight on the memory as possible.
Thanks a lot :slight_smile:

you already allocated a vert / horz Mat for you algo, it shouldn’t be more

if you need more it’s a trade-in , mem vs compute

1 Like

Thank you very much!
Helped me a lot.