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);
cv::imshow(" canny " , contours);
cv::meanStdDev(frame,mean,stddev);
stddevValue= stddev.at<uchar>(0,0);
if(!stddev.empty())
cv::imshow("stddev",stddev);
}
return 0;
}
any idea how i can solve this problem!
source
share