0

I wanted to convert a cv::MAT image to a CVD::Image but i don't know how can I do. The reason is because previously I had a CVD::Image and I transformed it to cv::MAT in order to set a ROI region in the image, and now, I need the picture in CVD. The code used to perform it, it's the following:

CVD::Image<CVD::byte> Imatge_a_modificar;
Imatge_a_modificar.copy_from(mimFrameBW_workingCopy); //The image is copied from another one

int x = frameWidth/2;
int y = frameHeight/2;

CvRect sROI = cvRect(x,y, frameWidth/2, frameHeight/2);

    int xroi = sROI.x;
    int yroi = sROI.y;

cv::Mat image(frameWidth,frameHeight,CV_8UC4,Imatge_a_modificar.data());
cv::Mat imageROI(image, sROI);
sashoalm
  • 75,001
  • 122
  • 434
  • 781
RMG
  • 1
  • 3
  • Why wouldn't you comment or accept my answer? – Mikhail Dec 11 '14 at 10:29
  • Sorry, I hadn't time untill now! I'll take a look, but I've syntax problems to define the basic image. CVD::BasicImage Image_2 = new BasicImage(Image1,CVD::ImageRef(Width,High),Width); But I've an error and I don't know which one! – RMG Dec 11 '14 at 17:56
  • You don't need `new` here. Just create object on the stack, as in the original code in your question. – Mikhail Dec 12 '14 at 08:27
  • @Mikhail thanks for your answer, but how should I convert opencv data unsigned char to CVD::Rgb ? they are all unsigned char actually, but the compiler complain about no suitable converter. I wrote : CVD::BasicImage > cvd_image((CVD::Rgb)frame.data, CVD::ImageRef(frame.cols,frame.rows)); – flankechen Oct 21 '15 at 04:31
  • @Mikhail I just figure it out, I make opencv mat from cvd image and use copyto to set this image from another mat. Mat cvd_image(frame.rows,frame.cols,CV_8UC3,(unsigned char*)imRGB.data()); cvtColor(frame, frame, CV_BGR2RGB); frame.copyTo(cvd_image); – flankechen Oct 21 '15 at 06:46

1 Answers1

0

First of all, use cv::Rect, not CvRect. The latter is the obsolete C type from OpenCV version 1.

Concerning your question, you need to create CVD::Image the same way you created cv::Mat - from a given bitmap buffer, where your actual pixel values are stored. To access bitmap buffer of cv::Mat use ptr() method. To construct CVD::Image from a buffer, use the corresponding CVD::BasicImage constructor, and then convert CVD::BasicImage to CVD::Image using CVD::Image::copy_from method.

Mikhail
  • 20,685
  • 7
  • 70
  • 146