Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create an image to hold a grayscale version
- IplImage grayImage = IplImage.create(grabbedImage.width(), grabbedImage.height(),
- opencv_core.IPL_DEPTH_8U, 1);
- IplImage cannyOutput = IplImage.create(grabbedImage.width(), grabbedImage.height(),
- opencv_core.IPL_DEPTH_8U, 1);
- IplImage color_dst = IplImage.create(grabbedImage.width(), grabbedImage.height(),
- opencv_core.IPL_DEPTH_8U, 3);
- //
- IplImage tmpl = cvLoadImage("vision_target.png");
- IplImage tmplp = IplImage.create(tmpl.width(), tmpl.height(),IPL_DEPTH_8U, 1);
- cvCvtColor(tmpl, tmplp, CV_RGB2GRAY);
- ObjectFinder matcher = new ObjectFinder(tmplp);
- CvSeq lines = new CvSeq();
- while ((grabbedImage = grabber.grab()) != null && keepGoing) {
- if (grabbedImage != null) {
- // Convert image to grayscale.
- cvCvtColor(grabbedImage, grayImage, CV_BGR2GRAY);
- /*double[] results = matcher.find(grayImage);
- if (results != null) {
- System.out.print("Hooray!");
- for (int i = 0; i < results.length; i++) {
- System.out.print(" " + (int)results[i]);
- }
- for (int i = 0; i < results.length; i+=2) {
- cvCircle(grabbedImage, cvPoint((int)results[i], (int)results[i + 1]),3, CvScalar.YELLOW, -1, CV_AA,
- 0);
- }
- System.out.println();
- } else {
- System.out.println("Fail :(");
- }*/
- // Run the pattern matcher
- /*CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1, 0);
- // iterate over the discovered faces and draw yellow
- // rectangles around them.
- for (int i = 0; i < faces.total(); i++) {
- CvRect r = new CvRect(cvGetSeqElem(faces, i));
- cvRectangle(grabbedImage, cvPoint(r.x(), r.y()),
- cvPoint(r.x() + r.width(), r.y() + r.height()), CvScalar.YELLOW, 1, CV_AA,
- 0);
- }*/
- cvCanny(grayImage, cannyOutput, 100, 230, 3);
- cvCvtColor( cannyOutput, color_dst, CV_GRAY2BGR );
- lines = cvHoughLines2(cannyOutput, storage, CV_HOUGH_PROBABILISTIC, 1, Math.PI / 180, 50, 10, 3);
- for (int i = 0; i <= lines.total(); i++) {
- // from JavaCPP, the equivalent of the C code:
- // CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
- // CvPoint first=line[0], second=line[1]
- // is:
- // CvPoint first=line.position(0), secon=line.position(1);
- Pointer line = cvGetSeqElem(lines, i);
- if (line == null || line.isNull())
- break;
- CvPoint pt1 = new CvPoint(line).position(0);
- CvPoint pt2 = new CvPoint(line).position(1);
- System.out.println("Line spotted: ");
- System.out.println("\t pt1: " + pt1);
- System.out.println("\t pt2: " + pt2);
- cvLine(color_dst, pt1, pt2, CV_RGB(255, 0, 0), 3, CV_AA, 0); // draw the segment on the image
- }
- /* HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
- for( size_t i = 0; i < lines.size(); i++ )
- {
- line( color_dst, Point(lines[i][0], lines[i][1]),
- Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
- }*/
- // Display it
- frame.showImage(color_dst);
- }
- }
- // Clean up
- grabber.release();
Add Comment
Please, Sign In to add comment