gpt4 book ai didi

c++ - 在opencv中以flo​​at格式获取stddev的值

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:02:57 27 4
gpt4 key购买 nike

我正在尝试获取保存在浮点变量中的帧的标准差值,这是我尝试过的:

#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;
}

知道我怎样才能解决这个问题!

最佳答案

我发现了错误:

而不是使用:stddevValue= stddev.at<uchar>(0,0);// here the program crashes
我不得不使用:stddevValue= stddev.at<double>(0,0);这有效!

关于c++ - 在opencv中以flo​​at格式获取stddev的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323267/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com