Ask Your Question
1

average value to int

asked 2016-07-13 18:44:10 -0600

HiHello gravatar image

updated 2016-07-14 06:42:57 -0600

LBerger gravatar image
Mat src_size;
src_size = imread("unit.jpg", 1);
cv::Scalar avg;
avg = cv::mean(src_size);

Mat dst_size(Size(256, 256), CV_64F);


for (int i = 0; i < 256; i++) {
    for (int j = 0; j < 256; j++) {
        dst_size.at<int>(i, j) = avg;
    }
}
imshow("Hi", dst_size);

How can i convert Scalar to int??

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-07-13 20:03:47 -0600

Tetragramm gravatar image

Scalar has four elements of default type double. As you can see from the documentation, which should be your first place to look, each element can be accessed by using the () operator.

double first = avg(0);
double second = avg(1);
...

The number of elements filled is equal to the number of channels in your image. In this case, only the first is filled.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-13 18:44:10 -0600

Seen: 843 times

Last updated: Jul 14 '16