Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

saving a frame using imwrite

Hi! I wrote a code to calcul the mean value and the standard deviation of multiple images, the code works fine I can see the standard deviation and the mean using imshow, but when I try to save them I get a black frame for the deviatframe here is the code :

cv::Mat frame,frame32f;
char filename[40];
cv::Mat mean;
const int count =4;
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);
}
deviationframe *= 1.0/(count -1);



cv::sqrt(deviationframe,deviationframe);
cv::imwrite("blblblb.tif",deviationframe);
cv::imwrite("mean.tif",resultframe);

deviationframe= deviationframe/15.96;
resultframe *= 1.0/255.0;
imshow("mean ",resultframe);
imshow("deviation frame ",deviationframe);

waitKey(0);
return 0;

} as I said Ican save the mean file without any problem but the deviation ????? thanks in advance