Java Code Examples for org.bytedeco.javacv.OpenCVFrameConverter#ToIplImage
The following examples show how to use
org.bytedeco.javacv.OpenCVFrameConverter#ToIplImage .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaarFaceDetector.java From javacv-cnn-example with MIT License | 6 votes |
public HaarFaceDetector() { iplImageConverter = new OpenCVFrameConverter.ToIplImage(); toMatConverter = new OpenCVFrameConverter.ToMat(); try { File haarCascade = new File(this.getClass().getResource("/detection/haarcascade_frontalface_alt.xml").toURI()); logger.debug("Using Haar Cascade file located at : {}", haarCascade.getAbsolutePath()); //haarClassifierCascade = new CvHaarClassifierCascade(cvload(haarCascade.getAbsolutePath())); faceCascade = new CascadeClassifier(haarCascade.getCanonicalPath()); } catch (Exception e) { logger.error("Error when trying to get the haar cascade", e); throw new IllegalStateException("Error when trying to get the haar cascade", e); } storage = CvMemStorage.create(); }
Example 2
Source File: ColoredObjectTracker.java From ExoVisix with MIT License | 5 votes |
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) { } }
Example 3
Source File: ColoredObjectTracker.java From ExoVisix with MIT License | 5 votes |
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; }
Example 4
Source File: ConverterUtil.java From marvinproject with GNU Lesser General Public License v3.0 | 5 votes |
public static IplImage bufferedToIplImage(BufferedImage bufImage) { ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage(); Java2DFrameConverter java2dConverter = new Java2DFrameConverter(); IplImage iplImage = iplConverter.convert(java2dConverter .convert(bufImage)); return iplImage; }
Example 5
Source File: VirtualBall.java From procamtracker with GNU General Public License v2.0 | 5 votes |
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)); } }
Example 6
Source File: Chronometer.java From procamtracker with GNU General Public License v2.0 | 5 votes |
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)); } }
Example 7
Source File: LivePlayTest2.java From oim-fx with MIT License | 4 votes |
/** * 转流器 * * @param inputFile * @param outputFile * @throws Exception * @throws org.bytedeco.javacv.FrameRecorder.Exception * @throws InterruptedException */ public static void recordPush(String inputFile, int v_rs) throws Exception, org.bytedeco.javacv.FrameRecorder.Exception, InterruptedException { Loader.load(opencv_objdetect.class); long startTime = 0; FrameGrabber grabber = FFmpegFrameGrabber.createDefault(inputFile); try { grabber.start(); } catch (Exception e) { try { grabber.restart(); } catch (Exception e1) { throw e; } } OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage(); Frame grabframe = grabber.grab(); IplImage grabbedImage = null; if (grabframe != null) { System.out.println("取到第一帧"); grabbedImage = converter.convert(grabframe); } else { System.out.println("没有取到第一帧"); } System.out.println("开始推流"); CanvasFrame frame = new CanvasFrame("camera", CanvasFrame.getDefaultGamma() / grabber.getGamma()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setAlwaysOnTop(true); while (frame.isVisible() && (grabframe = grabber.grab()) != null) { System.out.println("推流..."); frame.showImage(grabframe); grabbedImage = converter.convert(grabframe); Frame rotatedFrame = converter.convert(grabbedImage); if (startTime == 0) { startTime = System.currentTimeMillis(); } Thread.sleep(40); } frame.dispose(); grabber.stop(); System.exit(2); }
Example 8
Source File: CameraFlyCapture.java From PapARt with GNU Lesser General Public License v3.0 | 4 votes |
protected CameraFlyCapture(int cameraNo) { this.systemNumber = cameraNo; this.setPixelFormat(PixelFormat.BGR); converter = new OpenCVFrameConverter.ToIplImage(); }
Example 9
Source File: CameraOpenCV.java From PapARt with GNU Lesser General Public License v3.0 | 4 votes |
protected CameraOpenCV(int cameraNo) { this.systemNumber = cameraNo; this.setPixelFormat(PixelFormat.BGR); converter = new OpenCVFrameConverter.ToIplImage(); }
Example 10
Source File: CameraFFMPEG.java From PapARt with GNU Lesser General Public License v3.0 | 4 votes |
protected CameraFFMPEG(String description, String imFormat) { this.cameraDescription = description; // this.setPixelFormat(Camera.PixelFormat.RGB); this.imageFormat = imFormat; converter = new OpenCVFrameConverter.ToIplImage(); }
Example 11
Source File: ObjectFinder.java From PapARt with GNU Lesser General Public License v3.0 | 4 votes |
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(); }
Example 12
Source File: ConverterUtil.java From marvinproject with GNU Lesser General Public License v3.0 | 4 votes |
public static BufferedImage IplImageToBufferedImage(IplImage src) { OpenCVFrameConverter.ToIplImage grabberConverter = new OpenCVFrameConverter.ToIplImage(); Java2DFrameConverter paintConverter = new Java2DFrameConverter(); Frame frame = grabberConverter.convert(src); return paintConverter.getBufferedImage(frame, 1); }
Example 13
Source File: ConverterUtil.java From marvinproject with GNU Lesser General Public License v3.0 | 4 votes |
public static IplImage frametoIplImage(Frame frame) { OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage(); return converter.convert(frame); }
Example 14
Source File: CalibrationWorker.java From procamcalib with GNU General Public License v2.0 | 4 votes |
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); } }