2016-12-29 3 views
0

私はRGB画像を撮る。私はそれをベクトルに変換しようとします(コードは以下の通りです)。ベクトルを読むと、非常に大きな値または非常に小さな値が得られます。私はこれが関数から返されたベクトルと関係があると思いますが、それを理解することはできません。私は次のような値を取得する:2.36943e-38 2.36943e-38 -8256.25 -81920 などスカラーによるopencv行列除算は非常に大きい/小さい数を生成する

#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/opencv.hpp> 
#include <opencv2/highgui/highgui_c.h> 
#include <iostream> 
#include <string> 
#include <vector> 


using namespace cv; 
using namespace std; 

vector<float> mat_to_vec(Mat M){ 
    vector<float> array_temp; 

    for (int i=0;i<M.cols;i++){ 
    for(int j=0;j<M.rows;j++) 
    { 
     array_temp.push_back(M.at<float>(j,i)); 
    } 
} 
return array_temp; 
} 


int main(int argc, char** argv) 
{ 

// read the image 

Mat src=imread(argv[1],CV_LOAD_IMAGE_COLOR); 

// separate the channels 

Mat bgr[3]; //destination array 
split(src,bgr);//split source 

// convert to individual arrays and divide by 256 
Mat temp_b=bgr[0]/256.0; 
Mat temp_g=bgr[1]/256.0; 
Mat temp_r=bgr[2]/256.0; 

vector<float> array_b=mat_to_vec(temp_b); 
vector<float> array_g=mat_to_vec(temp_g); 
vector<float> array_r=mat_to_vec(temp_r); 

// merge the arrays 

vector<float> array_rgb; 
array_rgb.insert(array_rgb.end(), array_r.begin(), array_r.end()); 
array_rgb.insert(array_rgb.end(), array_g.begin(), array_g.end()); 
array_rgb.insert(array_rgb.end(), array_b.begin(), array_b.end()); 

for (int i=0; i<array_rgb.size();i++){ 
cout << array_rgb[i] << endl; 
} 
return 0;  
} 

答えて

1

あなたは要素型の画像、使用src.convertToをfloatに、あなたのsrc画像を変換する必要がある(SRC、CV_32FC1) ;

+0

あなたはCV_32FC3を意味しますか? – user27665

+0

チャンネルの数は変更されませんが、そうです、CV_32FC3が良く見えます。 –

関連する問題