How to cut a sub-part of an image using Emgu CV (or OpenCV)?

Kaveh Shahbazian picture Kaveh Shahbazian · Jun 29, 2011 · Viewed 26.2k times · Source

I want to cut a sub-purt of an image (or crop it) using Emgu CV (or OpenCV) and calculate average color of that part; looking for changes.

Thanks

Answer

Chris picture Chris · Jul 14, 2011
  1. Set the ROI (Region of Interest) of the image you are working with this will mean any calculation is only done over this area.

    image.ROI = new Rectangle(x,Y,Width,Height);

  2. Calculate the Average of the ROI where "TYPE" is image dependant Bgr for colour Gray for Grayscale

TYPE average = image.GetAverage(image);

  1. When youve finished reset your image ROI so you can see the whole image again.

All the process does is loop through each pixel adds its value then divides by the total number of pixels. Saves you writing the code yourself.

Thanks Chris