Go to Post I am not short, I am just conveniently packaged. - kio_chan176 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 17-02-2014, 18:10
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Vision Processing

If you have the weight for a coprocessor, it may be adventageous to go that route.

I've still got to wire my code into network tables, but that should be easy.

We spent days trying to get the onboard stuff working but as many have warned, it's really tough to do it well on the crio. We went to week zero with onboard code and had no problems seeing hot, anything more than that I would be concerned about.

If you're using robotbuilder / subsystems / commands, I can help you get up and running with some hot camera code. Shoot me an email and I'll invite you to my dropbox (mwtidd@gmail.com).

Here is the current version of my opencv code for java:

Code:
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JSlider;

import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfPoint;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
import org.opencv.imgproc.Imgproc;

public class MatchingDemo {
	
	public static void main(String[] args) throws InterruptedException {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
		
		JFrame frame1 = new JFrame("Camera");  
	    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
	    frame1.setSize(1260,720);  
	    frame1.setBounds(0, 0, 1260, 720);  
	    Panel panel1 = new Panel();  
	    frame1.setContentPane(panel1);  
	    frame1.setVisible(true);
	    
	    VideoCapture capture =new VideoCapture(0);  
	    capture.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 720);
	    capture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1260);
	    Mat src=new Mat(); 
	    
	    //BGR
	    Scalar rgb_min = new Scalar(0,0,50,0);
	    Scalar rgb_max = new Scalar(250,250,250,0);
		
		while(true){
			Thread.sleep(10);
			capture.read(src);
			
			Mat dest = new Mat();
			
			Core.inRange(src.clone(), rgb_min, rgb_max, dest);
			
	        Mat erode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3,3));
	        Mat dilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
	        
	   	 	
	        Imgproc.erode(dest, dest, erode);
	        Imgproc.erode(dest, dest, erode);
	        
	        Imgproc.dilate(dest, dest, dilate);
	        Imgproc.dilate(dest, dest, dilate);

	        List<MatOfPoint> contours = new ArrayList<MatOfPoint>();

	        Imgproc.findContours(dest, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
	        
	        MatOfPoint2f mMOP2f1 = new MatOfPoint2f();
			MatOfPoint2f mMOP2f2 = new MatOfPoint2f();
	        
			List<Rect> filteredTargets = new ArrayList<Rect>();
	        for(MatOfPoint contour : contours){
	        	
	        	contour.convertTo(mMOP2f1, CvType.CV_32FC2); 
	        	Imgproc.approxPolyDP(mMOP2f1, mMOP2f2, 2, true);
	        	Rect rectangle = Imgproc.boundingRect(contour);
	        	
	        	int area = rectangle.width * rectangle.height;
	        	double verticalRatio = rectangle.height / rectangle.width;
	        	double horizontalRatio = rectangle.width / rectangle.height;
	        
	        	if(rectangle.width * rectangle.height > 2500 && (verticalRatio > 2 || horizontalRatio > 2) ){
	        		filteredTargets.add(rectangle);
	        		System.out.println("The target is: " + rectangle.width + " x " + rectangle.height);
	        		
	        		Core.rectangle(src, rectangle.tl(), rectangle.br(), new Scalar(0,111,255,0));
	        	}
	        }
	        
	        System.out.println("Targets found: " + filteredTargets.size());
			
	        panel1.setimagewithMat(src);
			frame1.repaint();
			if(true) continue;
	   	 	
	   	 	
	   	 	
		}
    }
}
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:07.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi