domingo, 3 de agosto de 2014

First Project with OpenCV: inRange Code for detect objects.

Well the following code let us, to remove all of elements of the pictures that are not of our interest using OpenCV and Java. For realize it, its necesary to use the inRange method (more information here). The first step is to convert the image in HSV format and them apply the inRange code.

 import org.opencv.core.Core;  
 import org.opencv.core.Mat;  
 import org.opencv.core.Scalar;  
 import org.opencv.highgui.Highgui;  
 import org.opencv.highgui.VideoCapture;  
 import org.opencv.imgproc.Imgproc;  
 import values.MyIntegers;  
  * @author aldajo  
 public class InRange {  
   public static void main(String[] args) {  
     VideoCapture camera = new VideoCapture(1);  
     Mat framevideo = new Mat();;;  
     Highgui.imwrite("image.png", framevideo);  
     Highgui.imwrite("imageInRange.png", preproc(framevideo));  
   public static Mat preproc(Mat frame) {  
     Mat preprosMat = new Mat();  
     Imgproc.cvtColor(frame, preprosMat, Imgproc.COLOR_RGB2HSV);  
     Core.inRange(frame, new Scalar(242, 228,103),  
         new Scalar(255, 255, 255), preprosMat);  
     return preprosMat;  

I used the above code and I got the following pictures:

Of course, you need change the values of the range for achieve it...

I have configured NetBeans for use the OpenCV library...

1 comentario: