2017-05-23 1 views
0

이 코드를 실행하는 동안 계속 세그먼트 화 오류가 발생합니다. 데이터 유형을 변경하여 실행 해 보았습니다. uchar 및 float 바이트 수가 일치하지 않는 데이터 유형의 문제입니까? 그렇다면 어떻게해야할까요? 시도openCV를 사용하려고하는 동안 세그먼트가 잘못되었습니다.

 image.at<float>(w,h)=lumin; 

은 세 가지로 하나의 결과를 작성 :

#include "opencv2/highgui/highgui.hpp" 
#include <iostream> 

using namespace cv; 
using namespace std; 

int main(int argc, const char** argv) 
{ 
    Mat img = imread("/home/sahiti/Downloads/images3.png", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img' 

    if (img.empty()) //check whether the image is loaded or not 
    { 
      cout << "Error : Image cannot be loaded..!!" << endl; 
      //system("pause"); //wait for a key press 
      return -1; 
    } 

    Mat image; 
    img.convertTo(image,CV_32F); 
    int w,h; 
    for(w=0;w<img.size().width;w++) 
    { 

     for(h=0;h<img.size().height;h++) 
     { 

      Vec3f intensity = img.at<Vec3f>(w, h); 
      float blue = intensity.val[0]; 
      float green = intensity.val[1]; 
      float red = intensity.val[2]; 
      float lumin=(0.2126 * red + 0.7152 *green + 0.0722 *blue); 
      image.at<float>(w,h)=lumin; 
     } 
    } 
Mat im; 
image.convertTo(im,CV_8UC1); 
imwrite("/home/sahiti/gray_Image.png", im); 



    return 0; 
} 

답변

0

이 줄

Vec3f intensity = img.at<Vec3f>(w, h); 

또한이 이해가되지 않습니다

Vec3f intensity = image.at<Vec3f>(w, h); 

해야한다 채널 이미지. 더 이해할 수 있습니다.

#include "opencv2/highgui/highgui.hpp" 
#include <iostream> 

using namespace cv; 
using namespace std; 

int main(int argc, const char** argv) 
{ 
    Mat img = imread("/home/sahiti/Downloads/images3.png", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img' 

    if (img.empty()) //check whether the image is loaded or not 
    { 
      cout << "Error : Image cannot be loaded..!!" << endl; 
      //system("pause"); //wait for a key press 
      return -1; 
    } 

    Mat image; 
    Mat im(img.size(), CV_8UC1); 
    img.convertTo(image,CV_32F); 

    int w,h; 
    for(w=0;w<img.size().width;w++) 
    { 

     for(h=0;h<img.size().height;h++) 
     { 

      //Vec3f intensity = img.at<Vec3f>(w, h); 
      Vec3f intensity = image.at<Vec3f>(w, h); 
      float blue = intensity.val[0]; 
      float green = intensity.val[1]; 
      float red = intensity.val[2]; 
      float lumin=(0.2126 * red + 0.7152 *green + 0.0722 *blue); 
      //image.at<float>(w,h)=lumin; 
      im.at<uint8>(w,h)=lumin; 
     } 
    } 
    //Mat im; 
    //image.convertTo(im,CV_8UC1); 
    imwrite("/home/sahiti/gray_Image.png", im); 



    return 0; 
} 
관련 문제