1
저는 opencv의 초보자입니다.openCV 변경된 색상으로 이미지를 복사하지 않습니다 (opencv 및 C++)
새로운 이미지
규모를
넣어 회색으로 특정 이미지를 변환 0,0
에서 그 안에 어떤 이미지를 넣어 확인 : 나는이 작업을 옆의 그레이 스케일 된 이미지 (300, 0에서)
이것은 내가 한 일이다. 생성자와 모든 함수를 가진 클래스 imagehandler가 있습니다.
cv::Mat m_image
은 회원 필드입니다.
void imagehandler::rgb_to_greyscale(){
cv::cvtColor(m_image, m_image, CV_RGB2GRAY);
}
이가이다 : 이것은 그레이 스케일로 변환하는 기능이
imagehandler::imagehandler(const std::string& fileName)
: m_image(imread(fileName, CV_LOAD_IMAGE_COLOR))
{
if(!m_image.data)
{
cout << "Failed loading " << fileName << endl;
}
}
: 파일에서 이미지를 읽을 수
imagehandler::imagehandler(int width, int height)
: m_image(width, height, CV_8UC3){
}
생성자 :
생성자는 새 이미지를 만들려면 붙여 넣기 이미지를 복사하는 기능 :
//paste image to dst image at xloc,yloc
void imagehandler::copy_paste_image(imagehandler& dst, int xLoc, int yLoc){
cv::Rect roi(xLoc, yLoc, m_image.size().width, m_image.size().height);
cv::Mat imageROI (dst.m_image, roi);
m_image.copyTo(imageROI);
}
이제, 주,이 내가 무슨 짓을 :
imagehandler CSImg(600, 320); //declare the new image
imagehandler myimg(filepath);
myimg.copy_paste_image(CSImg, 0, 0);
CSImg.displayImage(); //this one showed the full colour image correctly
myimg.rgb_to_greyscale();
myimg.displayImage(); //this shows the colour image in GRAY scale, works correctly
myimg.copy_paste_image(CSImg, 300, 0);
CSImg.displayImage(); // this one shows only the full colour image at 0,0 and does NOT show the greyscaled one at ALL!
는 어떤 문제가 될 것 같다? 나는 이것에 몇 시간 동안 나의 머리를 긁고 있었다! 대신
{
m_image.create(width, height, CV_8UC3);
}
를 작성해야하고 기본 구성에 대해 걱정하지 마십시오 대신
m_image(width, height, CV_8UC3){}
의 생성자에서
:
근무했습니다. – TheNotMe