0

私はopencvにフレームを持っていますが、imwrite()を使用して保存したくないので、このコードを使用して各チャネルを抽出して保存し、3つのファイルを開いて、最初に新しいフレームを組み合わせると、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);
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";
    }
}
 .......

保存されたファイルは正しいので、フレームが1920 * 1080である方法で、SCILABを使用してそれらを開きます。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);/////////////////////////////////////////

これは私が得る縞模様の画像の一部ですここに画像の説明を入力してください:あなたの助けに感謝します

4

2 に答える 2

0

Ted 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();
于 2013-02-20T09:09:20.077 に答える
0

幅と高さのパラメータが逆になっているようです。画像が入れ替わっている可能性があります。

于 2013-02-19T14:43:17.390 に答える