1

OpenCVを使用して、複数の写真の標準偏差を取得しようとしています。ここで私が行ったこと:

#include #include #include

 using namespace std;
  using namespace cv;

 int main(){
cv::Mat frame,frame32f;
char filename[40];
cv::Mat mean;
const int count =134;
const int width  = 1920;
const int height = 1080;
cv::Mat resultframe = cv::Mat::zeros(height,width,CV_32FC3);
cv::Mat deviationframe = cv::Mat ::zeros(height,width,CV_32FC3);
cv::Mat temp = cv::Mat ::zeros(height,width,CV_32FC3);
for(int i = 1 ; i<= count; i++){
//int i = 3;
sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",i);
frame = imread(filename,CV_LOAD_IMAGE_COLOR);
frame.convertTo(frame32f,CV_32FC3 );
resultframe +=frame32f;
frame.release();
}
resultframe *= (1.0/count);
for(int j =1; j<count; j++){
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",j);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3);
    temp =(frame32f - resultframe);
    deviationframe+= temp.mul(temp);

    //temp.release();
}
imshow("devi",deviationframe);  // works
deviationframe *= 1.0/(count -1);
imshow("devi2",deviationframe); // works
cv::sqrt(deviationframe,deviationframe);
resultframe *= 1.0/255.0;
imshow("devi3",deviationframe);// works
deviationframe *= 1.0/255.0;

imshow("mean ",resultframe);
imshow("deviation frame ",deviationframe);// BLACK FRAME !!!!!!!!!!!!!!!!!!!
    waitKey(0);
return 0;

}

結果フレームの「平均値」は正しいですが、標準偏差は間違っています。私が何を間違っているのか、事前に助けてくれてありがとう

4

2 に答える 2

1

標準偏差を計算するために、差分二乗画像の結果を累積していません。現在のコードの結果は、最後の画像のみが二乗され、画像の総数で除算されます。以前の計算はすべて無効です。

また、除算は画像の視覚化255のみを目的としており、実際の計算用ではありません。標準偏差を計算する前に 255 で除算しているため、結果が不正確になります。

コードを次のように変更します。

.
.
.
resultframe *= (1.0/count);
cv::Mat deviationResult = cv::Mat::zeros(height,width,CV_32FC3);

for(int j =1; j< count; j++)
{
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",j);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3);
    deviationframe =(frame32f - resultframe);
    deviationResult += deviationframe.mul(deviationframe);
}
resultframe *= (1.0/255.0);
deviationResult = deviationResult /(count -1 );
cv::sqrt(deviationResult ,deviationResult );
deviationResult *= (1.0/255.0);
imshow("mean ",resultframe);
imshow("deviation frame ",deviationResult);
waitKey(0);
return 0;
于 2013-02-14T11:35:44.117 に答える
0

@ sgar91の助けの後、これが最終的なコードです。誰かの役に立てば幸いです

 #include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\opencv.hpp>
#include <stdlib.h>

using namespace std;
using namespace cv;

 int main(){
cv::Mat frame,frame32f;
char filename[40];
cv::Mat mean;
const int count =134;
const int width  = 1920;
const int height = 1080;
cv::Mat resultframe = cv::Mat::zeros(height,width,CV_32FC3);
cv::Mat deviationframe = cv::Mat ::zeros(height,width,CV_32FC3);
cv::Mat temp = cv::Mat ::zeros(height,width,CV_32FC3);
for(int i = 1 ; i<= count; i++){
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",i);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3 );
    resultframe +=frame32f;
    frame.release();
}
resultframe *= (1.0/count);
for(int j =1; j<count; j++){
    sprintf(filename,"d:\\BMdvideos\\images\\image%d.tiff",j);
    frame = imread(filename,CV_LOAD_IMAGE_COLOR);
    frame.convertTo(frame32f,CV_32FC3);
    temp =(frame32f - resultframe);
    deviationframe+= temp.mul(temp);

    //temp.release();
}
deviationframe *= 1.0/(count -1);

deviationframe= deviationframe/255;
cv::sqrt(deviationframe,deviationframe);
resultframe *= 1.0/255.0;
imshow("mean ",resultframe);
imshow("deviation frame ",deviationframe);
waitKey(0);
return 0;
 }
于 2013-02-14T14:45:30.707 に答える