org.bytedeco.javacv.Frame Java Examples

The following examples show how to use org.bytedeco.javacv.Frame. 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: LivePlayTest.java    From oim-fx with MIT License 8 votes vote down vote up
private static void recordByFrame(FFmpegFrameGrabber grabber, FFmpegFrameRecorder recorder, Boolean status)
		throws Exception, org.bytedeco.javacv.FrameRecorder.Exception {
	try {// 建议在线程中使用该方法
		grabber.start();
		recorder.start();
		Frame frame = null;
		while (status && (frame = grabber.grabFrame()) != null) {
			recorder.record(frame);
		}
		recorder.stop();
		grabber.stop();
	} finally {
		if (grabber != null) {
			grabber.stop();
		}
	}
}
 
Example #2
Source File: LivePlayTest3.java    From oim-fx with MIT License 7 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
				Image image = bufferedImage;
				ImageIcon icon = new ImageIcon(image);
				playLabel.setIcon(icon);
			}
		}

	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example #3
Source File: CameraVideoPanel.java    From oim-fx with MIT License 6 votes vote down vote up
public Frame getFrame() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
				Image image = bufferedImage;
				ImageIcon icon = new ImageIcon(image);
				iconLabel.setIcon(icon);
			}
		}

	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return capturedFrame;
}
 
Example #4
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 3);
    Frame frame = writable.getFrame();
    ImageTransform transform = new MultiImageTransform(rng, new CropImageTransform(10),
                    new FlipImageTransform(), new ScaleImageTransform(10), new WarpImageTransform(10));

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight >= frame.imageHeight - 30);
        assertTrue(f.imageHeight <= frame.imageHeight + 20);
        assertTrue(f.imageWidth >= frame.imageWidth - 30);
        assertTrue(f.imageWidth <= frame.imageWidth + 20);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new MultiImageTransform(new ColorConversionTransform(COLOR_BGR2RGB));
    writable = transform.transform(writable);
    float[] transformed = transform.query(new float[] {11, 22});
    assertEquals(11, transformed[0], 0);
    assertEquals(22, transformed[1], 0);
}
 
Example #5
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testFilterImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 4);
    Frame frame = writable.getFrame();
    ImageTransform transform = new FilterImageTransform("noise=alls=20:allf=t+u,format=rgba", frame.imageWidth,
                    frame.imageHeight, frame.imageChannels);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertEquals(f.imageHeight, frame.imageHeight);
        assertEquals(f.imageWidth, frame.imageWidth);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));
}
 
Example #6
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testScaleImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 4);
    Frame frame = writable.getFrame();
    ImageTransform transform = new ScaleImageTransform(rng, frame.imageWidth / 2, frame.imageHeight / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight >= frame.imageHeight / 2);
        assertTrue(f.imageHeight <= 3 * frame.imageHeight / 2);
        assertTrue(f.imageWidth >= frame.imageWidth / 2);
        assertTrue(f.imageWidth <= 3 * frame.imageWidth / 2);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new ScaleImageTransform(frame.imageWidth, 2 * frame.imageHeight);
    writable = transform.transform(writable);
    float[] coordinates = {5, 7, 11, 13};
    float[] transformed = transform.query(coordinates);
    assertEquals(5 * 2,  transformed[0], 0);
    assertEquals(7 * 3,  transformed[1], 0);
    assertEquals(11 * 2, transformed[2], 0);
    assertEquals(13 * 3, transformed[3], 0);
}
 
Example #7
Source File: HaarFaceDetector.java    From javacv-cnn-example with MIT License 6 votes vote down vote up
/**
 * Detects and returns a map of cropped faces from a given captured frame
 *
 * @param frame the frame captured by the {@link org.bytedeco.javacv.FrameGrabber}
 * @return A map of faces along with their coordinates in the frame
 */
public Map<Rect, Mat> detect(Frame frame) {
    Map<Rect, Mat> detectedFaces = new HashMap<>();

    /*
     * return a CV Sequence (kind of a list) with coordinates of rectangle face area.
     * (returns coordinates of left top corner & right bottom corner)
     */
    //CvSeq detectObjects = cvHaarDetectObjects(iplImage, haarClassifierCascade, storage, 1.5, 3, CV_HAAR_DO_CANNY_PRUNING);
    RectVector detectObjects = new RectVector();

    Mat matImage = toMatConverter.convert(frame);
    faceCascade.detectMultiScale(matImage, detectObjects);

    long numberOfPeople = detectObjects.size();
    for (int i = 0; i < numberOfPeople; i++) {
        Rect rect = detectObjects.get(i);
        Mat croppedMat = matImage.apply(new Rect(rect.x(), rect.y(), rect.width(), rect.height()));
        detectedFaces.put(rect, croppedMat);
    }

    return detectedFaces;
}
 
Example #8
Source File: NativeAudioRecordReader.java    From DataVec with Apache License 2.0 6 votes vote down vote up
protected List<Writable> loadData(File file, InputStream inputStream) throws IOException {
    List<Writable> ret = new ArrayList<>();
    try (FFmpegFrameGrabber grabber = inputStream != null ? new FFmpegFrameGrabber(inputStream)
                    : new FFmpegFrameGrabber(file.getAbsolutePath())) {
        grabber.setSampleFormat(AV_SAMPLE_FMT_FLT);
        grabber.start();
        Frame frame;
        while ((frame = grabber.grab()) != null) {
            while (frame.samples != null && frame.samples[0].hasRemaining()) {
                for (int i = 0; i < frame.samples.length; i++) {
                    ret.add(new FloatWritable(((FloatBuffer) frame.samples[i]).get()));
                }
            }
        }
    }
    return ret;
}
 
Example #9
Source File: ImageUtils.java    From javacv-cnn-example with MIT License 6 votes vote down vote up
/**
 * Method to get resized buffered image when user passes the relevant frame and video panel.
 *
 * @param frame      frame to be converted to {@link BufferedImage}
 * @param videoPanel the {@link JPanel} which is to be used to obtain panel size
 * @return resized {@link BufferedImage}
 */
public static BufferedImage getResizedBufferedImage(Frame frame, JPanel videoPanel) {
    BufferedImage resizedImage = null;

    try {
        /*
         * We get notified about the frames that are being added. Then we pass each frame to BufferedImage. I have used
         * a library called Thumbnailator to achieve the resizing effect along with performance
         */
        resizedImage = Thumbnails.of(frameConverter.getBufferedImage(frame))
                .size(videoPanel.getWidth(), videoPanel.getHeight())
                .asBufferedImage();
    } catch (IOException e) {
        logger.error("Unable to convert the image to a buffered image", e);
    }

    return resizedImage;
}
 
Example #10
Source File: TestImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testScaleImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 4);
    Frame frame = writable.getFrame();
    ImageTransform transform = new ScaleImageTransform(rng, frame.imageWidth / 2, frame.imageHeight / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight >= frame.imageHeight / 2);
        assertTrue(f.imageHeight <= 3 * frame.imageHeight / 2);
        assertTrue(f.imageWidth >= frame.imageWidth / 2);
        assertTrue(f.imageWidth <= 3 * frame.imageWidth / 2);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new ScaleImageTransform(frame.imageWidth, 2 * frame.imageHeight);
    writable = transform.transform(writable);
    float[] coordinates = {5, 7, 11, 13};
    float[] transformed = transform.query(coordinates);
    assertEquals(5 * 2,  transformed[0], 0);
    assertEquals(7 * 3,  transformed[1], 0);
    assertEquals(11 * 2, transformed[2], 0);
    assertEquals(13 * 3, transformed[3], 0);
}
 
Example #11
Source File: ResizeImageTransformTest.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeUpscale1() throws Exception {
    ImageWritable srcImg = TestImageTransform.makeRandomImage(32, 32, 3);

    ResizeImageTransform transform = new ResizeImageTransform(200, 200);

    ImageWritable dstImg = transform.transform(srcImg);

    Frame f = dstImg.getFrame();
    assertEquals(f.imageWidth, 200);
    assertEquals(f.imageHeight, 200);

    float[] coordinates = {100, 200};
    float[] transformed = transform.query(coordinates);
    assertEquals(200f * 100 / 32, transformed[0], 0);
    assertEquals(200f * 200 / 32, transformed[1], 0);
}
 
Example #12
Source File: CNNGenderDetector.java    From javacv-cnn-example with MIT License 6 votes vote down vote up
/**
 * Predicts gender of a given cropped face
 *
 * @param face  the cropped face as a {@link Mat}
 * @param frame the original frame where the face was cropped from
 * @return Gender
 */
public Gender predictGender(Mat face, Frame frame) {
    try {
        Mat croppedMat = new Mat();
        resize(face, croppedMat, new Size(256, 256));
        normalize(croppedMat, croppedMat, 0, Math.pow(2, frame.imageDepth), NORM_MINMAX, -1, null);

        Mat inputBlob = blobFromImage(croppedMat);
        genderNet.setInput(inputBlob, "data", 1.0, null);      //set the network input

        Mat prob = genderNet.forward("prob");

        Indexer indexer = prob.createIndexer();
        logger.debug("CNN results {},{}", indexer.getDouble(0, 0), indexer.getDouble(0, 1));
        if (indexer.getDouble(0, 0) > indexer.getDouble(0, 1)) {
            logger.debug("Male detected");
            return Gender.MALE;
        } else {
            logger.debug("Female detected");
            return Gender.FEMALE;
        }
    } catch (Exception e) {
        logger.error("Error when processing gender", e);
    }
    return Gender.NOT_RECOGNIZED;
}
 
Example #13
Source File: ResizeImageTransformTest.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeDownscale() throws Exception {
    ImageWritable srcImg = TestImageTransform.makeRandomImage(571, 443, 3);

    ResizeImageTransform transform = new ResizeImageTransform(200, 200);

    ImageWritable dstImg = transform.transform(srcImg);

    Frame f = dstImg.getFrame();
    assertEquals(f.imageWidth, 200);
    assertEquals(f.imageHeight, 200);

    float[] coordinates = {300, 400};
    float[] transformed = transform.query(coordinates);
    assertEquals(200f * 300 / 443, transformed[0], 0);
    assertEquals(200f * 400 / 571, transformed[1], 0);
}
 
Example #14
Source File: ResizeImageTransformTest.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testResizeDownscale() throws Exception {
    ImageWritable srcImg = TestImageTransform.makeRandomImage(571, 443, 3);

    ResizeImageTransform transform = new ResizeImageTransform(200, 200);

    ImageWritable dstImg = transform.transform(srcImg);

    Frame f = dstImg.getFrame();
    assertEquals(f.imageWidth, 200);
    assertEquals(f.imageHeight, 200);

    float[] coordinates = {300, 400};
    float[] transformed = transform.query(coordinates);
    assertEquals(200f * 300 / 443, transformed[0], 0);
    assertEquals(200f * 400 / 571, transformed[1], 0);
}
 
Example #15
Source File: TestImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testCropImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 1);
    Frame frame = writable.getFrame();
    ImageTransform transform = new CropImageTransform(rng, frame.imageHeight / 2, frame.imageWidth / 2,
                    frame.imageHeight / 2, frame.imageWidth / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight <= frame.imageHeight);
        assertTrue(f.imageWidth <= frame.imageWidth);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new CropImageTransform(1, 2, 3, 4);
    writable = transform.transform(writable);
    float[] coordinates = {1, 2, 3, 4};
    float[] transformed = transform.query(coordinates);
    assertEquals(1 - 2, transformed[0], 0);
    assertEquals(2 - 1, transformed[1], 0);
    assertEquals(3 - 2, transformed[2], 0);
    assertEquals(4 - 1, transformed[3], 0);
}
 
Example #16
Source File: ImageWritable.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (obj instanceof ImageWritable) {
        Frame f2 = ((ImageWritable) obj).getFrame();

        Buffer[] b1 = this.frame.image;
        Buffer[] b2 = f2.image;

        if (b1.length != b2.length)
            return false;

        for (int i = 0; i < b1.length; i++) {
            if (!b1[i].equals(b2[i]))
                return false;
        }

        return true;
    } else {
        return false;
    }
}
 
Example #17
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testRotateImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 1);
    Frame frame = writable.getFrame();
    ImageTransform transform =
                    new RotateImageTransform(rng, 180).interMode(INTER_NEAREST).borderMode(BORDER_REFLECT);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertEquals(f.imageHeight, frame.imageHeight);
        assertEquals(f.imageWidth, frame.imageWidth);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new RotateImageTransform(0, 0, -90, 0);
    writable = transform.transform(writable);
    float[] coordinates = {frame.imageWidth / 2, frame.imageHeight / 2, 0, 0};
    float[] transformed = transform.query(coordinates);
    assertEquals(frame.imageWidth  / 2, transformed[0], 0);
    assertEquals(frame.imageHeight / 2, transformed[1], 0);
    assertEquals((frame.imageHeight + frame.imageWidth) / 2, transformed[2], 1);
    assertEquals((frame.imageHeight - frame.imageWidth) / 2, transformed[3], 1);
}
 
Example #18
Source File: CameraVideoPanel.java    From oim-fx with MIT License 6 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
				Image image = bufferedImage;
				ImageIcon icon = new ImageIcon(image);
				iconLabel.setIcon(icon);
			}
		}

	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example #19
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testRandomCropTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 1);
    Frame frame = writable.getFrame();
    ImageTransform transform = new RandomCropTransform(frame.imageHeight / 2, frame.imageWidth / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight == frame.imageHeight / 2);
        assertTrue(f.imageWidth == frame.imageWidth / 2);
    }
    assertEquals(null, transform.transform(null));

    transform = new RandomCropTransform(frame.imageHeight, frame.imageWidth);
    writable = transform.transform(writable);
    float[] coordinates = {2, 4, 6, 8};
    float[] transformed = transform.query(coordinates);
    assertEquals(2, transformed[0], 0);
    assertEquals(4, transformed[1], 0);
    assertEquals(6, transformed[2], 0);
    assertEquals(8, transformed[3], 0);
}
 
Example #20
Source File: LivePlayTest2.java    From oim-fx with MIT License 6 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
				Image image = bufferedImage;
				ImageIcon icon = new ImageIcon(image);
				playLabel.setIcon(icon);
			}
		}

	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example #21
Source File: LivePlayTest.java    From oim-fx with MIT License 6 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
				Image image = bufferedImage;
				ImageIcon icon = new ImageIcon(image);
				playLabel.setIcon(icon);
			}
		}

	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example #22
Source File: CameraVideo.java    From oim-fx with MIT License 6 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
			}
		}
	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example #23
Source File: TestImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testRandomCropTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 1);
    Frame frame = writable.getFrame();
    ImageTransform transform = new RandomCropTransform(frame.imageHeight / 2, frame.imageWidth / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight == frame.imageHeight / 2);
        assertTrue(f.imageWidth == frame.imageWidth / 2);
    }
    assertEquals(null, transform.transform(null));

    transform = new RandomCropTransform(frame.imageHeight, frame.imageWidth);
    writable = transform.transform(writable);
    float[] coordinates = {2, 4, 6, 8};
    float[] transformed = transform.query(coordinates);
    assertEquals(2, transformed[0], 0);
    assertEquals(4, transformed[1], 0);
    assertEquals(6, transformed[2], 0);
    assertEquals(8, transformed[3], 0);
}
 
Example #24
Source File: TestImageTransform.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCropImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 1);
    Frame frame = writable.getFrame();
    ImageTransform transform = new CropImageTransform(rng, frame.imageHeight / 2, frame.imageWidth / 2,
                    frame.imageHeight / 2, frame.imageWidth / 2);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight <= frame.imageHeight);
        assertTrue(f.imageWidth <= frame.imageWidth);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new CropImageTransform(1, 2, 3, 4);
    writable = transform.transform(writable);
    float[] coordinates = {1, 2, 3, 4};
    float[] transformed = transform.query(coordinates);
    assertEquals(1 - 2, transformed[0], 0);
    assertEquals(2 - 1, transformed[1], 0);
    assertEquals(3 - 2, transformed[2], 0);
    assertEquals(4 - 1, transformed[3], 0);
}
 
Example #25
Source File: Recorder.java    From VideoAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if (mFrame != null && mRecording) {
        ((ByteBuffer)mFrame.image[0].position(0)).put(data);

        try {
            long t = 1000 * (System.currentTimeMillis() - mStartTime);
            if (t > mFFmpegFrameRecorder.getTimestamp()) {
                mFFmpegFrameRecorder.setTimestamp(t);
            }

            mFFmpegFrameFilter.push(mFrame);
            Frame frame2;
            while ((frame2 = mFFmpegFrameFilter.pull()) != null) {
                mFFmpegFrameRecorder.record(frame2);            //录制该图片
            }
        } catch (FFmpegFrameRecorder.Exception | FrameFilter.Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example #26
Source File: JavaCVReadAVI.java    From Data_Processor with Apache License 2.0 6 votes vote down vote up
public void run() throws Exception, InterruptedException {
		FFmpegFrameGrabber ffmpegFrameGrabber = FFmpegFrameGrabber.createDefault("C:/Users/Administrator/Desktop/deta/detasource/videoProcess/webwxgetvideo.avi");
		ffmpegFrameGrabber.start();
//		int fflength = ffmpegFrameGrabber.getLengthInFrames();
//		int maxStamp = (int) (ffmpegFrameGrabber.getLengthInTime()/1000000);
//		int count = 0;
		while (true) {
			Frame nowFrame = ffmpegFrameGrabber.grabImage();
//			int startStamp = (int) (ffmpegFrameGrabber.getTimestamp() * 1.0/1000000);
//			double present = (startStamp * 1.0 / maxStamp) * 100;
			if (nowFrame == null) {
				System.out.println("!!! Failed cvQueryFrame");
				continue;
			}
			Java2DFrameConverter paintConverter = new Java2DFrameConverter();
			BufferedImage difImage = paintConverter.getBufferedImage(nowFrame, 1);
			paint(difImage);
			Thread.sleep(25);
		}
	}
 
Example #27
Source File: Yolo.java    From Java-Machine-Learning-for-Computer-Vision with MIT License 6 votes vote down vote up
public void drawBoundingBoxesRectangles(Frame frame, Mat matFrame, String windowName) throws Exception {
    if (invalidData(frame, matFrame) || outputFrames) return;
    if (previousPredictedObjects == null) {
        previousPredictedObjects.addAll(predictedObjects);
    }
    ArrayList<MarkedObject> detectedObjects = predictedObjects == null ? new ArrayList<>() : new ArrayList<>(predictedObjects);

    for (MarkedObject markedObjects : detectedObjects) {
        try {
            createBoundingBoxRectangle(matFrame, markedObjects);
            imshow(windowName, matFrame);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("Problem with out of the bounds image");
            imshow(windowName, matFrame);
        }
    }
    previousPredictedObjects.addAll(detectedObjects);

    if (detectedObjects.isEmpty())
        imshow(windowName, matFrame);

}
 
Example #28
Source File: TestImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Ignore
@Test
public void testFilterImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 4);
    Frame frame = writable.getFrame();
    ImageTransform transform = new FilterImageTransform("noise=alls=20:allf=t+u,format=rgba", frame.imageWidth,
                    frame.imageHeight, frame.imageChannels);

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertEquals(f.imageHeight, frame.imageHeight);
        assertEquals(f.imageWidth, frame.imageWidth);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));
}
 
Example #29
Source File: ImageWritable.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object obj) {
    if (obj instanceof ImageWritable) {
        Frame f2 = ((ImageWritable) obj).getFrame();

        Buffer[] b1 = this.frame.image;
        Buffer[] b2 = f2.image;

        if (b1.length != b2.length)
            return false;

        for (int i = 0; i < b1.length; i++) {
            if (!b1[i].equals(b2[i]))
                return false;
        }

        return true;
    } else {
        return false;
    }
}
 
Example #30
Source File: TestImageTransform.java    From DataVec with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiImageTransform() throws Exception {
    ImageWritable writable = makeRandomImage(0, 0, 3);
    Frame frame = writable.getFrame();
    ImageTransform transform = new MultiImageTransform(rng, new CropImageTransform(10),
                    new FlipImageTransform(), new ScaleImageTransform(10), new WarpImageTransform(10));

    for (int i = 0; i < 100; i++) {
        ImageWritable w = transform.transform(writable);
        Frame f = w.getFrame();
        assertTrue(f.imageHeight >= frame.imageHeight - 30);
        assertTrue(f.imageHeight <= frame.imageHeight + 20);
        assertTrue(f.imageWidth >= frame.imageWidth - 30);
        assertTrue(f.imageWidth <= frame.imageWidth + 20);
        assertEquals(f.imageChannels, frame.imageChannels);
    }
    assertEquals(null, transform.transform(null));

    transform = new MultiImageTransform(new ColorConversionTransform(COLOR_BGR2RGB));
    writable = transform.transform(writable);
    float[] transformed = transform.query(new float[] {11, 22});
    assertEquals(11, transformed[0], 0);
    assertEquals(22, transformed[1], 0);
}