|
Re: Vision Processing
Quote:
Originally Posted by lineskier
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;
}
}
}
|
Thanks a ton! I'll shoot you an email in just a second.
We were looking at OpenCV as well, but when I downloaded it, my computer refused to open it, so I wasn't sure what to do.
__________________
|