Sunday, 15 September 2013

How to get a correct marked image using ROI with javacv

How to get a correct marked image using ROI with javacv

I have run this code and This code give the black image instead of the ROI
marked image,can I please know the wrong with this code please.
public class ROITest {
private static final String OUT_FILE = "img\\ROI.jpg";
public static void main(String[] args)
{
opencv_core.CvRect r =new opencv_core.CvRect();
args[0]="img\\2.jpg";
if (args.length != 1) {
System.out.println("Usage: run FaceDetection <input-file>");
return;
}
// preload the opencv_objdetect module to work around a known bug
// Loader.load(opencv_objdetect.class);
Loader.load(opencv_core.class);
// load an image
System.out.println("Loading image from " + args[0]);
IplImage origImg = cvLoadImage(args[0]);
// IplImage ROIimg = CvSetImageROI(origImg, opencv_core.cvRect(0, 0,
640, 480));
cvSetImageROI(origImg, cvRect(1,1, origImg.width(), origImg.height()));
IplImage ROIimg = IplImage.create(cvGetSize(origImg),origImg.depth(),
origImg.nChannels());
cvCopy(ROIimg,origImg);
cvSaveImage(OUT_FILE, ROIimg);
final IplImage image = cvLoadImage(OUT_FILE);
CanvasFrame canvas = new CanvasFrame("Region of Interest");
cvResetImageROI(image);
canvas.showImage(image);
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
}
It gives a completely black image instead of marked image..

No comments:

Post a Comment