Crop Image C++ using Rect() Map()

Hi Everyone!

I hope someone can help me with an issue I’m facing when cropping an image. I’m using the Rect() function to define a rectangle for cropping and the Map() function to crop the image.

When I use Rect(0, 0, 100, 100), the CreateImageMap() function successfully creates the cropped image for display. However, when I try to move the rectangle by defining it as Rect(5, 0, 100, 100) (to shift the cropping region), I get an error in the CreateImageMap() function.

ERROR: C-API call failed; try getting a log by using CVB LogGUI/silogutil: {“Name”: “CreateImageMap”, “CVC_ERROR_CODE”: 1}

Has anyone encountered a similar issue or know why this happens when changing the x or y coordinates of the rectangle?

Thanks in advance for your help!

Hi Emma,

I have tested the functionality with CVB 14.1.000 and it works as expected. You can find the C++ code below. I will test it with the latest CVB version and update you here.

int main()
{

  try
  {
    const auto baseName  = Cvb::String("FruitBowl");
    const auto extension = Cvb::String(".bmp");
    const Cvb::String fileName = Cvb::InstallPath() + Cvb::String("tutorial/") + baseName + Cvb::String("Bayer") + extension;
    std::unique_ptr<Cvb::Image> originalImage = Cvb::Image::Load(fileName);
    Cvb::Rect<int> cropRect(50, 50, 200, 200);
    std::unique_ptr<Cvb::Image> croppedImage = originalImage->Map(cropRect);
    croppedImage->Save("./cropped.bmp");

  }
  catch (const std::exception &error)
  {
    std::cout << error.what() << std::endl;
  }
  return 0;
}
1 Like

@Emma I tested with CVB 14.1.002, it works as well.

Thanks for the update :slight_smile: