getting the value of stddev in float format in opencv
c++, opencv
Solution
I've found the error :
instead of using : `stddevValue= stddev.at<uchar>(0,0);// here the program crashes ` I had to use : `stddevValue= stddev.at<double>(0,0);` this works!
Problem
I'm trying to get the value of the standard deviation of frame saved in a float variable, here's what I've tried : ``` #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp> #include <iostream> int main (){ cv::Mat frame,thresholdResult,contours, stddev , mean ; cv::Mat meanResult; cv::Scalar meanScalar,devScalar; double meanValue,stddevValue; cv::VideoCapture cap(2); cap >> frame; meanResult= cv::Mat::zeros (frame.rows,frame.cols,CV_32FC1); while (cv::waitKey(10)!=27){ cap >> frame; cv::cvtColor(frame,frame,CV_BGR2GRAY); cv::imshow("frame", frame); meanScalar = cv::mean(frame); meanValue = meanScalar[0]; std::cout <<meanValue << std::endl; cv::threshold(frame,thresholdResult,meanValue,255,CV_THRESH_BINARY); cv::imshow("threshold result " , thresholdResult); cv::blur(thresholdResult,thresholdResult,cv::Size(3,3)); cv::Canny(thresholdResult,contours,125,350); // canny cv::imshow(" canny " , contours); cv::meanStdDev(frame,mean,stddev); // stddev number of channels is stddevValue= stddev.at<uchar>(0,0);// here the program crashes if(!stddev.empty()) cv::imshow("stddev",stddev); } return 0; } ``` any idea how can I get this solve !