当前位置: 首页>>代码示例>>Java>>正文


Java OpenCVFrameConverter.ToIplImage方法代码示例

本文整理汇总了Java中org.bytedeco.javacv.OpenCVFrameConverter.ToIplImage方法的典型用法代码示例。如果您正苦于以下问题:Java OpenCVFrameConverter.ToIplImage方法的具体用法?Java OpenCVFrameConverter.ToIplImage怎么用?Java OpenCVFrameConverter.ToIplImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bytedeco.javacv.OpenCVFrameConverter的用法示例。


在下文中一共展示了OpenCVFrameConverter.ToIplImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public void run() {
	try {
		grabber = FrameGrabber.createDefault(CAMERA_NUM);
		converter = new OpenCVFrameConverter.ToIplImage();
		grabber.start();

		int posX = 0;
		int posY = 0;
		while (true) {
			img = converter.convert(grabber.grab());
			if (img != null) {
				// show image on window
				cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
				canvas.showImage(converter.convert(img));
				IplImage detectThrs = getThresholdImage(img);

				CvMoments moments = new CvMoments();
				cvMoments(detectThrs, moments, 1);

				double mom10 = cvGetSpatialMoment(moments, 1, 0);
				double mom01 = cvGetSpatialMoment(moments, 0, 1);
				double area = cvGetCentralMoment(moments, 0, 0);
				posX = (int) (mom10 / area);
				posY = (int) (mom01 / area);
				// only if its a valid position
				if (posX > 0 && posY > 0) {
					paint(img, posX, posY);
				}
			}
			// Thread.sleep(INTERVAL);
		}
	} catch (Exception e) {
	}
}
 
开发者ID:MeAnupSarkar,项目名称:ExoVisix,代码行数:35,代码来源:ColoredObjectTracker.java

示例2: Equalize

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public IplImage Equalize(BufferedImage bufferedimg) {
	Java2DFrameConverter converter1 = new Java2DFrameConverter();
	OpenCVFrameConverter.ToIplImage converter2 = new OpenCVFrameConverter.ToIplImage();
	IplImage iploriginal = converter2.convert(converter1.convert(bufferedimg));
	IplImage srcimg = IplImage.create(iploriginal.width(), iploriginal.height(), IPL_DEPTH_8U, 1);
	IplImage destimg = IplImage.create(iploriginal.width(), iploriginal.height(), IPL_DEPTH_8U, 1);
	cvCvtColor(iploriginal, srcimg, CV_BGR2GRAY);
	cvEqualizeHist(srcimg, destimg);
	return destimg;
}
 
开发者ID:MeAnupSarkar,项目名称:ExoVisix,代码行数:11,代码来源:ColoredObjectTracker.java

示例3: BufferedImageToIplImage

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static IplImage BufferedImageToIplImage(BufferedImage src) {
  OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
  Java2DFrameConverter jconverter = new Java2DFrameConverter();
  return grabberConverter.convert(jconverter.convert(src));
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:6,代码来源:Vision.java

示例4: IplImageToBufferedImage

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static BufferedImage IplImageToBufferedImage(IplImage src) {
  OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
  Java2DFrameConverter converter = new Java2DFrameConverter();
  Frame frame = grabberConverter.convert(src);
  return converter.getBufferedImage(frame, 1);
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:7,代码来源:Vision.java

示例5: show

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public void show(final Mat imageMat, final String title) {
  IplImage image = converterToIpl.convertToIplImage(converterToIpl.convert(imageMat));
  final IplImage image1 = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, image.nChannels());
  cvCopy(image, image1);
  CanvasFrame canvas = new CanvasFrame(title, 1);
  canvas.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  final OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
  canvas.showImage(converter.convert(image1));
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:10,代码来源:OpenCVFilterFaceRecognizer.java

示例6: IplImageToBufferedImage

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
/**
 * new way of converting IplImages to BufferedImages
 * 
 * @param src
 * @return
 */
public static BufferedImage IplImageToBufferedImage(IplImage src) {
	OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage();
	Java2DFrameConverter converter = new Java2DFrameConverter();
	Frame frame = grabberConverter.convert(src);
	return converter.getBufferedImage(frame, 1);
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:13,代码来源:OpenCVUtils.java

示例7: main

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
        CanvasFrame frame = new CanvasFrame("Virtual Ball Test");
        OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
        IplImage image = IplImage.create(640, 960, IPL_DEPTH_8U, 3);
        cvSetZero(image);
        double[] roiPts = { 0,0, 640,0, 640,480, 0,400 };
        cvFillConvexPoly(image, new CvPoint(4).put((byte)16, roiPts), roiPts.length/2, CvScalar.WHITE, CV_AA, 16);
        VirtualBall virtualBall = new VirtualBall(new Settings(roiPts));

        for (int i = 0; i < 1000; i++) {
            Thread.sleep(100);
            cvSetZero(image);
            if (i == 50) {
                roiPts[5] -= 100;
            }
            if (i > 100 && i < 1200) {
                roiPts[3] += 1;
                roiPts[5] += 1;
            }
//if (i > 103) {
//    System.out.println(i);
//}
            cvFillConvexPoly(image, new CvPoint(4).put((byte)16, roiPts), roiPts.length/2, CvScalar.WHITE, CV_AA, 16);
            virtualBall.draw(image, roiPts);
            frame.showImage(converter.convert(image));
        }
    }
 
开发者ID:bytedeco,项目名称:procamtracker,代码行数:28,代码来源:VirtualBall.java

示例8: Chronometer

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
Chronometer(Rectangle roi, IplImage image, long startTime) {
    this.roi = (Rectangle)roi.clone();
    this.startTime = startTime;
    this.converter = new OpenCVFrameConverter.ToIplImage();
    this.chronoImage = new BufferedImage(roi.width, roi.height, Java2DFrameConverter.getBufferedImageType(converter.convert(image)));
    this.chronoGraphics = (Graphics2D)chronoImage.getGraphics();

    Font bigFont, smallFont;
    FontMetrics bigFontMetrics;
    Rectangle2D bounds;
    int fontSize = 10;
    do {
        bigFont   = new Font("Sans", Font.BOLD, fontSize);
        smallFont = new Font("Sans", Font.BOLD, fontSize*9/10);
        bigFontMetrics = chronoGraphics.getFontMetrics(bigFont);
        bounds = bigFontMetrics.getStringBounds("0′00″0", chronoGraphics);
        fontSize += 1;
    } while (bounds.getWidth()*1.1 < roi.width && bounds.getHeight()*1.1 < roi.height);
    this.bigFont = bigFont;
    this.smallFont = smallFont;
    this.bigFontMetrics = bigFontMetrics;
    this.bounds = bounds;

    chronoGraphics.setBackground(Color.WHITE);
    chronoGraphics.setColor(Color.BLACK);
    chronoGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
 
开发者ID:bytedeco,项目名称:procamtracker,代码行数:28,代码来源:Chronometer.java

示例9: main

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    CanvasFrame frame = new CanvasFrame("Chronometer Test");
    OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
    IplImage image = IplImage.create(640, 480, IPL_DEPTH_8U, 3);
    cvSetZero(image);
    Chronometer chronometer = new Chronometer(new Rectangle(100, 100, 100, 100), image);

    for (int i = 0; i < 1000; i++) {
        Thread.sleep(100);
        cvSetZero(image);
        chronometer.draw(image);
        frame.showImage(converter.convert(image));
    }
}
 
开发者ID:bytedeco,项目名称:procamtracker,代码行数:15,代码来源:Chronometer.java

示例10: CameraFlyCapture

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
protected CameraFlyCapture(int cameraNo) {
    this.systemNumber = cameraNo;
    this.setPixelFormat(PixelFormat.BGR);
    converter = new OpenCVFrameConverter.ToIplImage();
}
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:6,代码来源:CameraFlyCapture.java

示例11: CameraOpenCV

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
protected CameraOpenCV(int cameraNo) {
    this.systemNumber = cameraNo;
    this.setPixelFormat(PixelFormat.BGR);
    converter = new OpenCVFrameConverter.ToIplImage();
}
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:6,代码来源:CameraOpenCV.java

示例12: CameraFFMPEG

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
protected CameraFFMPEG(String description, String imFormat) {
        this.cameraDescription = description;
//        this.setPixelFormat(Camera.PixelFormat.RGB);
        this.imageFormat = imFormat;
        converter = new OpenCVFrameConverter.ToIplImage();
    }
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:7,代码来源:CameraFFMPEG.java

示例13: main

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
//        Logger.getLogger("org.bytedeco.javacv").setLevel(Level.OFF);

//        String objectFilename = args.length == 2 ? args[0] : "/home/jiii/sketchbook/libraries/PapARt/data/markers/dlink.png";
        String objectFilename = args.length == 2 ? args[0] : "/home/jiii/repos/Papart-github/papart-examples/Camera/ExtractPlanarObjectForTracking/ExtractedView.bmp";
        String sceneFilename = args.length == 2 ? args[1] : "/home/jiii/my_photo-7.jpg";

        IplImage object = cvLoadImage(objectFilename, CV_LOAD_IMAGE_GRAYSCALE);
        IplImage image = cvLoadImage(sceneFilename, CV_LOAD_IMAGE_GRAYSCALE);
        if (object == null || image == null) {
            System.err.println("Can not load " + objectFilename + " and/or " + sceneFilename);
            System.exit(-1);
        }

        IplImage objectColor = IplImage.create(object.width(), object.height(), 8, 3);
        cvCvtColor(object, objectColor, CV_GRAY2BGR);

        IplImage correspond = IplImage.create(image.width(), object.height() + image.height(), 8, 1);
        cvSetImageROI(correspond, cvRect(0, 0, object.width(), object.height()));
        cvCopy(object, correspond);
        cvSetImageROI(correspond, cvRect(0, object.height(), correspond.width(), correspond.height()));
        cvCopy(image, correspond);
        cvResetImageROI(correspond);

        ObjectFinder.Settings settings = new ObjectFinder.Settings();
        settings.objectImage = object;
        settings.useFLANN = true;
        settings.ransacReprojThreshold = 5;
        ObjectFinder finder = new ObjectFinder(settings);

        long start = System.currentTimeMillis();
        double[] dst_corners = finder.find(image);
//        System.out.println("Finding time = " + (System.currentTimeMillis() - start) + " ms");

        if (dst_corners != null) {
            for (int i = 0; i < 4; i++) {
                int j = (i + 1) % 4;
                int x1 = (int) Math.round(dst_corners[2 * i]);
                int y1 = (int) Math.round(dst_corners[2 * i + 1]);
                int x2 = (int) Math.round(dst_corners[2 * j]);
                int y2 = (int) Math.round(dst_corners[2 * j + 1]);
                line(cvarrToMat(correspond), new Point(x1, y1 + object.height()),
                        new Point(x2, y2 + object.height()),
                        Scalar.WHITE, 1, 8, 0);
            }
        }

        for (int i = 0; i < finder.ptpairs.size(); i += 2) {
            Point2f pt1 = finder.objectKeypoints.get(finder.ptpairs.get(i)).pt();
            Point2f pt2 = finder.imageKeypoints.get(finder.ptpairs.get(i + 1)).pt();
            line(cvarrToMat(correspond), new Point(Math.round(pt1.x()), Math.round(pt1.y())),
                    new Point(Math.round(pt2.x()), Math.round(pt2.y() + object.height())),
                    Scalar.WHITE, 1, 8, 0);
        }

        CanvasFrame objectFrame = new CanvasFrame("Object");
        CanvasFrame correspondFrame = new CanvasFrame("Object Correspond");
        OpenCVFrameConverter converter = new OpenCVFrameConverter.ToIplImage();

        correspondFrame.showImage(converter.convert(correspond));
        for (int i = 0; i < finder.objectKeypoints.size(); i++) {
            KeyPoint r = finder.objectKeypoints.get(i);
            Point center = new Point(Math.round(r.pt().x()), Math.round(r.pt().y()));
            int radius = Math.round(r.size() / 2);
            circle(cvarrToMat(objectColor), center, radius, Scalar.RED, 1, 8, 0);
        }
        objectFrame.showImage(converter.convert(objectColor));

        objectFrame.waitKey();

        objectFrame.dispose();
        correspondFrame.dispose();
    }
 
开发者ID:poqudrof,项目名称:PapARt,代码行数:74,代码来源:ObjectFinder.java

示例14: main

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
//        Logger.getLogger("org.bytedeco.javacv").setLevel(Level.OFF);

//        String objectFilename = args.length == 2 ? args[0] : "/home/jiii/sketchbook/libraries/PapARt/data/markers/dlink.png";
        String objectFilename = args.length == 2 ? args[0] : "/home/jiii/sketchbook/libraries/PapARt/data/markers/rocks.jpg";
        String sceneFilename  = args.length == 2 ? args[1] : "/home/jiii/my_photo-4.jpg";

        IplImage object = cvLoadImage(objectFilename, CV_LOAD_IMAGE_GRAYSCALE);
        IplImage image  = cvLoadImage(sceneFilename,  CV_LOAD_IMAGE_GRAYSCALE);
        if (object == null || image == null) {
            System.err.println("Can not load " + objectFilename + " and/or " + sceneFilename);
            System.exit(-1);
        }

        IplImage objectColor = IplImage.create(object.width(), object.height(), 8, 3);
        cvCvtColor(object, objectColor, CV_GRAY2BGR);

        IplImage correspond = IplImage.create(image.width(), object.height()+ image.height(), 8, 1);
        cvSetImageROI(correspond, cvRect(0, 0, object.width(), object.height()));
        cvCopy(object, correspond);
        cvSetImageROI(correspond, cvRect(0, object.height(), correspond.width(), correspond.height()));
        cvCopy(image, correspond);
        cvResetImageROI(correspond);

        ObjectFinder.Settings settings = new ObjectFinder.Settings();
        settings.objectImage = object;
        settings.useFLANN = true;
        settings.ransacReprojThreshold = 5;
        ObjectFinder finder = new ObjectFinder(settings);

        long start = System.currentTimeMillis();
        double[] dst_corners = finder.find(image);
        System.out.println("Finding time = " + (System.currentTimeMillis() - start) + " ms");

        if (dst_corners !=  null) {
            for (int i = 0; i < 4; i++) {
                int j = (i+1)%4;
                int x1 = (int)Math.round(dst_corners[2*i    ]);
                int y1 = (int)Math.round(dst_corners[2*i + 1]);
                int x2 = (int)Math.round(dst_corners[2*j    ]);
                int y2 = (int)Math.round(dst_corners[2*j + 1]);
                line(cvarrToMat(correspond), new Point(x1, y1 + object.height()),
                        new Point(x2, y2 + object.height()),
                        Scalar.WHITE, 1, 8, 0);
            }
        }

        for (int i = 0; i < finder.ptpairs.size(); i += 2) {
            Point2f pt1 = finder.objectKeypoints.get(finder.ptpairs.get(i)).pt();
            Point2f pt2 = finder.imageKeypoints.get(finder.ptpairs.get(i + 1)).pt();
            line(cvarrToMat(correspond), new Point(Math.round(pt1.x()), Math.round(pt1.y())),
                    new Point(Math.round(pt2.x()), Math.round(pt2.y() + object.height())),
                    Scalar.WHITE, 1, 8, 0);
        }

        CanvasFrame objectFrame = new CanvasFrame("Object");
        CanvasFrame correspondFrame = new CanvasFrame("Object Correspond");
        OpenCVFrameConverter converter = new OpenCVFrameConverter.ToIplImage();

        correspondFrame.showImage(converter.convert(correspond));
        for (int i = 0; i < finder.objectKeypoints.size(); i++) {
            KeyPoint r = finder.objectKeypoints.get(i);
            Point center = new Point(Math.round(r.pt().x()), Math.round(r.pt().y()));
            int radius = Math.round(r.size() / 2);
            circle(cvarrToMat(objectColor), center, radius, Scalar.RED, 1, 8, 0);
        }
        objectFrame.showImage(converter.convert(objectColor));

        objectFrame.waitKey();

        objectFrame.dispose();
        correspondFrame.dispose();
    }
 
开发者ID:poqudrof,项目名称:PapAR,代码行数:74,代码来源:ObjectFinder.java

示例15: init

import org.bytedeco.javacv.OpenCVFrameConverter; //导入方法依赖的package包/类
public void init() throws Exception {
    // create arrays and canvas frames on the Event Dispatcher Thread...
    CameraDevice.Settings[] cs = cameraSettings.toArray();
    if (cameraDevices == null) {
        cameraDevices = new CameraDevice[cs.length];
    } else {
        cameraDevices = Arrays.copyOf(cameraDevices, cs.length);
    }
    cameraCanvasFrames = new CanvasFrame[cs.length];
    frameGrabbers = new FrameGrabber[cs.length];
    cameraFrameConverters = new OpenCVFrameConverter.ToIplImage[cs.length];
    for (int i = 0; i < cs.length; i++) {
        if (cameraDevices[i] == null) {
            cameraDevices[i] = new CameraDevice(cs[i]);
        } else {
            cameraDevices[i].setSettings(cs[i]);
        }
        if (cameraSettings.getMonitorWindowsScale() > 0) {
            cameraCanvasFrames[i] = new CanvasFrame(cs[i].getName());
            cameraCanvasFrames[i].setCanvasScale(cameraSettings.getMonitorWindowsScale());
        }
    }

    ProjectorDevice.Settings[] ps = projectorSettings.toArray();
    if (projectorDevices == null) {
        projectorDevices = new ProjectorDevice[ps.length];
    } else {
        projectorDevices = Arrays.copyOf(projectorDevices, ps.length);
    }
    projectorCanvasFrames = new CanvasFrame[ps.length];
    projectorPlanes = new MarkedPlane[ps.length];
    projectorFrameConverters = new OpenCVFrameConverter.ToIplImage[ps.length];
    for (int i = 0; i < ps.length; i++) {
        if (projectorDevices[i] == null) {
            projectorDevices[i] = new ProjectorDevice(ps[i]);
        } else {
            projectorDevices[i].setSettings(ps[i]);
        }
        projectorCanvasFrames[i] = projectorDevices[i].createCanvasFrame();
        projectorCanvasFrames[i].showColor(Color.BLACK);
        projectorFrameConverters[i] = new OpenCVFrameConverter.ToIplImage();
        Dimension dim = projectorCanvasFrames[i].getSize();
        projectorPlanes[i] = new MarkedPlane(dim.width, dim.height, markers[1], true,
                cvScalarAll(((ProjectorDevice.CalibrationSettings)ps[0]).getBrightnessForeground()*255),
                cvScalarAll(((ProjectorDevice.CalibrationSettings)ps[0]).getBrightnessBackground()*255), 4);
    }
}
 
开发者ID:bytedeco,项目名称:procamcalib,代码行数:48,代码来源:CalibrationWorker.java


注:本文中的org.bytedeco.javacv.OpenCVFrameConverter.ToIplImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。