Last active
October 21, 2018 14:46
-
-
Save zudov/4967792 to your computer and use it in GitHub Desktop.
Crop image using javacv.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.googlecode.javacv.cpp.opencv_core.cvCopy; | |
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage; | |
import static com.googlecode.javacv.cpp.opencv_core.cvGetSize; | |
import static com.googlecode.javacv.cpp.opencv_core.cvSetImageROI; | |
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage; | |
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage; | |
import com.googlecode.javacv.cpp.opencv_core.CvRect; | |
import com.googlecode.javacv.cpp.opencv_core.IplImage; | |
public class Cropper { | |
public static void main(String[] args) { | |
IplImage orig = cvLoadImage("orig.png"); | |
// Creating rectangle by which bounds image will be cropped | |
CvRect r = new CvRect(100, 100, 200, 200); | |
// After setting ROI (Region-Of-Interest) all processing will only be done on the ROI | |
cvSetImageROI(orig, r); | |
IplImage cropped = cvCreateImage(cvGetSize(orig), orig.depth(), orig.nChannels()); | |
// Copy original image (only ROI) to the cropped image | |
cvCopy(orig, cropped); | |
cvSaveImage("cropped.png", cropped); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
in the last changes of the javacv lib, the Rect constructor not accecpt int,int,int,int, you need set manually like this
CvRect rect = new CvRect();
rect.x(100);
rect.y(100);
rect.width(200);
rect.height(200);
Tnx for your job!