Getting stddev value in float format in opencv

I am trying to get the standard deviation value of a frame stored in a float variable, here is what I 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 i can solve this problem!

+4
source share
1 answer

I found an error:

instead of using: stddevValue= stddev.at<uchar>(0,0);// here the program crashes I had to use: stddevValue= stddev.at<double>(0,0);it works!

+3
source

All Articles