2013-02-19 97 views
0

我在opencv中有一個框架,我不想使用imwrite()保存,我使用此代碼來提取每個通道並保存它,並打開這三個文件併合並新框架的第一個位置是C++代碼:cv :: Mat框架和SCILAB

......... 
    mean_fb.open("d:\\mean_blue",ios::out); 
ostream osb(&mean_fb); 
mean_fg.open("d:\\mean_green",ios::out); 
ostream osg(&mean_fg); 
mean_fr.open("d:\\mean_red",ios::out); 
ostream osr(&mean_fr); 
resultframe *= 1.0/255.0; // adjusting the colors of the mean value 
for(int row = 0; row < resultframe.rows; row++) { 
    for (int col = 0; col < resultframe.cols; col++) { 
    // std::cout << resultframe.at<cv::Vec3f>(row, col)[1] <<std::endl; 
     std::cout << resultframe.at<cv::Vec3f>(row, col)[2] <<std::endl; 

     //fwrite(&resultframe.at<cv::Vec3f>(row,col)[0],sizeof(float),1,inpR); 
     osr<< resultframe.at<cv::Vec3f>(row, col)[0]<<"\n"; 
     osg<< resultframe.at<cv::Vec3f>(row, col)[1]<<"\n"; 
     osb<< resultframe.at<cv::Vec3f>(row, col)[2]<<"\n"; 
    } 
} 
....... 

保存的文件是正確的,所以我打開他們使用SCILAB由幀爲1920 * 1080的路上,這裏是SCILAB代碼:

clear 
    clc 
    stacksize('max'); 
    cd 'd:\' 
    width = 1080; 
    height =1920 ; 
    im = zeros(width, height); 
    // read the values of the red channel 

    red = mgetl('mean_red'); // read the file as 
    red = matrix(red,[width, height]); 
    red = strtod(red); 
    im(:,:,3) = red;// because opencv defaullt color Model is BGR 
    clear red; // clear red to get enough stack 



    // read the values of the green channel 

green = mgetl('mean_green'); // read the file as 
green = matrix(green,[width,height]); 
green = strtod(green); 
im(:,:,2) = green; 
    clear green; 


    // read the values of the blue channel 

    blue = mgetl(mean_blue'); // read the file as 
    blue = matrix(blue,[width, height]); 
    blue = strtod(blue); 
    im(:,:,1) =blue ; 
    clear blue; 


imshow(im);///////////////////////////////////////// 

這是我獲得的條紋圖像的一部分enter image description here: 感謝您的幫助

+0

什麼是你的問題?你已經描述了一個場景,沒有問過一個問題。你有什麼問題 ?你想要什麼答案? – Chani 2013-02-19 14:40:42

+0

獲取的圖像是條紋的,這是我的問題 – Engine 2013-02-19 14:41:23

回答

0

看來你得到的寬度和高度參數相反。圖像可能會被調換。

+0

我試過其他方式,但它的確切幫助,但圖像被切割 – Engine 2013-02-19 14:50:49

+0

當切換寬度和高度我得到正確的分辨率,只是一個圖像的aprt? – Engine 2013-02-19 15:04:18

+0

您是否也計算了3個顏色通道的大小以及可能的alpha通道? – 2013-02-19 15:46:25

0

特德W¯¯的建議後,我想,也許我不得不切換寬度和高度不SCILAB但在C++和這個工作所以這裏是代碼,如果有人需要它:

mean_fb.open("d:\\mean_blue",ios::out); 
ostream osb(&mean_fb); 
mean_fg.open("d:\\mean_green",ios::out); 
ostream osg(&mean_fg); 
mean_fr.open("d:\\mean_red",ios::out); 
ostream osr(&mean_fr); 
    adjusting the colors of the mean value 
for (int col = 0; col < resultframe.cols; col++) { 
    for(int row = 0; row < resultframe.rows; row++) { 
    // std::cout << resultframe.at<cv::Vec3f>(row, col)[1] <<std::endl; 
     std::cout << resultframe.at<cv::Vec3f>(row, col)[2] <<std::endl; 

     //fwrite(&resultframe.at<cv::Vec3f>(row,col)[0],sizeof(float),1,inpR); 
     osb<< resultframe.at<cv::Vec3f>(row, col)[0]<<"\n"; 
     osg<< resultframe.at<cv::Vec3f>(row, col)[1]<<"\n"; 
     osr<< resultframe.at<cv::Vec3f>(row, col)[2]<<"\n"; 
    } 
} 
mean_fb.close(); 
mean_fr.close(); 
mean_fg.close(); 


std_fb.open("d:\\std_blue",ios::out); 
ostream std_osb(&std_fb); 
std_fg.open("d:\\std_green",ios::out); 
ostream std_osg(&std_fg); 
std_fr.open("d:\\std_red",ios::out); 
ostream std_osr(&std_fr); 

for (int col = 0; col < deviationframe.cols; col++) { 
    for(int row = 0; row < deviationframe.rows; row++) { 

     std::cout << deviationframe.at<cv::Vec3f>(row, col)[2] <<std::endl; 
     std_osb<< deviationframe.at<cv::Vec3f>(row, col)[0]<<"\n"; 
     std_osg<< deviationframe.at<cv::Vec3f>(row, col)[1]<<"\n"; 
     std_osr<< deviationframe.at<cv::Vec3f>(row, col)[2]<<"\n"; 
    } 
} 
std_fb.close(); 
std_fr.close(); 
std_fg.close();