All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neuronrobotics.imageprovider.OpenCVTest Maven / Gradle / Ivy

There is a newer version: 0.50.1
Show newest version
package com.neuronrobotics.imageprovider;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javafx.scene.control.Tab;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.features2d.KeyPoint;

import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;

// any java file starting with i is the interface

public class OpenCVTest  {
	private ArrayList detectors;
	private RGBColorDetector mainFilter;

	public void run() { 
		
		File harr = null;
		try {
			harr = ScriptingEngine.fileFromGit("https://github.com/madhephaestus/DefaultHaarCascade.git",
													"haarcascade_frontalface_default.xml");
		} catch (InvalidRemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransportException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (GitAPIException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		HaarDetector faceDetectorObject = new HaarDetector(harr);

		BufferedImage inputImage = AbstractImageProvider.newBufferImage(640,480);
		BufferedImage displayImage =  AbstractImageProvider.newBufferImage(640,480);
		
		JFrame frame = new JFrame();

		JTabbedPane  tabs = new JTabbedPane();
		frame .setContentPane(tabs);
		frame.setSize(640, 580);
		frame.setVisible(true);
		frame .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		detectors = new ArrayList();
		ArrayList imageProviders = new ArrayList();
		ArrayList iconsCaptured = new ArrayList();
		ArrayList iconsProcessed = new ArrayList();
		
		Scalar upper =new Scalar(30, 150, 0, 0);
		Scalar lower =new Scalar(240, 166, 0, 0);
		
		Scalar upper1 =new Scalar(360, 255, 255, 0);
		Scalar lower1 =new Scalar(240, 0, 0, 0);
		
		
		imageProviders.add(new OpenCVImageProvider(0));               // Image provider
		imageProviders.get(0).getLatestImage(inputImage,displayImage);
		// Provides the static file to the processors
		imageProviders.add(new StaticFileProvider(new File("image.png")));
		
		
//		mainFilter = new RGBColorDetector(inputImage, 
//				lower,
//				upper, 
//				lower1, 
//				upper1);

		//add human detector later
		//detectors.add(faceDetectorObject);
		detectors.add(new SalientDetector());
		//detectors.add(new WhiteBlobDetect((int) upper.val[0],(int) upper.val[1], lower));
		Tab t = new Tab();
		
		int x=0;
		for (AbstractImageProvider img:imageProviders){
			img.getLatestImage(inputImage,displayImage);
			
			ImageIcon tmp = new ImageIcon(img.getLatestImage());
			iconsCaptured.add(tmp);
			
			tabs.addTab("Camera "+x, new JLabel(tmp));
			
			for (int i=0;i data = detectors.get(j).getObjects(inputImage, displayImage);
						iconsProcessed.get(i*j).setImage(displayImage);	// show processed image
						
						//System.out.println("Got: "+data.length);
						
					}
					frame.repaint();
				}
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}   
	  }

	/**
	 * @param args
	 */
	public static void main(String[] args) { // Main entry for object detection 
		
        
        new OpenCVTest().run();              // starts
	}


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy