Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to crop a Mat to ROI in Emgu (OpenCV for C#)

Some of the answers I found recommended using :

frame = ...
Rectangle ROI = ...
Mat crop = new Mat(frame, ROI) 

But this does not seem to wokr in Emgu 3.x

like image 387
Ahmed Avatar asked Feb 02 '26 15:02

Ahmed


1 Answers

Ahmed, you really do not have to create an Image<> just to create a Mat. Try the following:

Mat myNewMat = new Mat(input, crop_region);

Since you do not have a RotatedRect you do not have to translate the rotated rectangle into an upright rectangle. So you can just create a new Mat from your existing Mat and the rectangle.

This should work and can simplify your code some.

Doug

like image 199
AeroClassics Avatar answered Feb 05 '26 06:02

AeroClassics



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!