- Home /
how to crop image using opencv
Is there an option to crop the image using OpencvUnity package.I can resize but not crop.Kindly help
It's been a while since I've used OpenCV, but I would think you could just resize the matrix [$$anonymous$$atrix::resize()]. Or, if you don't want it anchored to a particular corner, copy the desired indices to a new matrix.
Answer by SolomonG · Jul 06, 2017 at 04:38 PM
Shouldn't be too hard. The OpenCVUnity package is essentially bindings to the Java OpenCV library, so what works in the Java library should work in the Unity one.
Rect rectCrop = new Rect(cropCenterX, cropCenterY, cropWidth, cropHeight);
Mat croppedImage = new Mat(originalImage, rectCrop);
Let me know if that worked or not!
@SolomonG Thanks. I worked. Yet my cropped image exceeds the scale factor(x:256,y:256,z:1) of Quad(3d game object in unity). $$anonymous$$y original image(Lena.jpg) size:512x512 and my cropped region size is 35x112. Why the cropped image seems to occupy the full region.
Your answer
![](https://koobas.hobune.stream/wayback/20220612125649im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
jibjab (insert your own face) implementation in Unity 0 Answers
Crop UI image and convert it as Sprite 1 Answer
Splitting an image to puzzle pieces 2 Answers
polygon crop an image 0 Answers