boofcv.struct.image.ImageType Java Examples

The following examples show how to use boofcv.struct.image.ImageType. 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: ContourBoundingBox.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public BufferedImage getTransformedImage(BufferedImage in, boolean flip)
{
       try
       {
           Planar<GrayF32> input = ConvertBufferedImage.convertFromPlanar(in, null, true, GrayF32.class);

           RemovePerspectiveDistortion<Planar<GrayF32>> removePerspective =
                   new RemovePerspectiveDistortion<>(300, 418, ImageType.pl(3, GrayF32.class));

           int start = longEdge();

           if(flip)
           {
               start = (start+2)%4;
           }

           if( !removePerspective.apply(input,
                   new Point2D_F64(corners[start].x,corners[start].y),
                   new Point2D_F64(corners[(start+1)%4].x,corners[(start+1)%4].y),
                   new Point2D_F64(corners[(start+2)%4].x,corners[(start+2)%4].y),
                   new Point2D_F64(corners[(start+3)%4].x,corners[(start+3)%4].y)
                                   ) ){
               return null;
           }
           Planar<GrayF32> output = removePerspective.getOutput();
           return ConvertBufferedImage.convertTo_F32(output,null,true);
       }
	catch(Exception e)
	{
		return null;
	}
}
 
Example #2
Source File: PathList.java    From cineast with MIT License 4 votes vote down vote up
public static LinkedList<Pair<Integer, ArrayList<AssociatedPair>>> getDensePaths(List<VideoFrame> videoFrames) {
    if (videoFrames.size() < 2) {
        return null;
    }

    PkltConfig configKlt = new PkltConfig(3, new int[]{1, 2, 4});
    configKlt.config.maxPerPixelError = 45;
    ImageGradient<GrayU8, GrayS16> gradient = FactoryDerivative.sobel(GrayU8.class, GrayS16.class);
    PyramidDiscrete<GrayU8> pyramidForeward = FactoryPyramid.discreteGaussian(configKlt.pyramidScaling, -1, 2, true, ImageType.single(GrayU8.class));
    PyramidDiscrete<GrayU8> pyramidBackward = FactoryPyramid.discreteGaussian(configKlt.pyramidScaling, -1, 2, true, ImageType.single(GrayU8.class));
    PyramidKltTracker<GrayU8, GrayS16> trackerForeward = FactoryTrackerAlg.kltPyramid(configKlt.config, GrayU8.class, null);
    PyramidKltTracker<GrayU8, GrayS16> trackerBackward = FactoryTrackerAlg.kltPyramid(configKlt.config, GrayU8.class, null);

    GrayS16[] derivX = null;
    GrayS16[] derivY = null;

    LinkedList<PyramidKltFeature> tracks = new LinkedList<PyramidKltFeature>();
    LinkedList<Pair<Integer, ArrayList<AssociatedPair>>> paths = new LinkedList<Pair<Integer, ArrayList<AssociatedPair>>>();

    GrayU8 gray = null;
    int frameIdx = 0;
    int cnt = 0;
    for (VideoFrame videoFrame : videoFrames) {
        ++frameIdx;

        if (cnt >= frameInterval) {
            cnt = 0;
            continue;
        }
        cnt += 1;

        gray = ConvertBufferedImage.convertFrom(videoFrame.getImage().getBufferedImage(), gray);
        ArrayList<AssociatedPair> tracksPairs = new ArrayList<AssociatedPair>();

        if (frameIdx == 0) {
            tracks = denseSampling(gray, derivX, derivY, samplingInterval, configKlt, gradient, pyramidBackward, trackerBackward);
        } else {
            tracking(gray, derivX, derivY, tracks, tracksPairs, gradient, pyramidForeward, pyramidBackward, trackerForeward, trackerBackward);
            tracks = denseSampling(gray, derivX, derivY, samplingInterval, configKlt, gradient, pyramidBackward, trackerBackward);
        }

        paths.add(new Pair<Integer, ArrayList<AssociatedPair>>(frameIdx, tracksPairs));
    }
    return paths;
}
 
Example #3
Source File: HOGHelper.java    From cineast with MIT License 3 votes vote down vote up
/**
 * Returns HOG descriptors for an image using the provided settings.
 *
 * @param image Image for which to obtain the HOG descriptors.
 * @param config ConfigDenseHog object that specifies the parameters for the HOG algorithm.
 * @return DescribeImageDense object containing the HOG descriptor.
 */
public static DescribeImageDense<GrayU8,TupleDesc_F64> getHOGDescriptors(BufferedImage image, ConfigDenseHoG config) {
    GrayU8 gray = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
    DescribeImageDense<GrayU8,TupleDesc_F64> desc = FactoryDescribeImageDense.hog(config, ImageType.single(GrayU8.class));
    desc.process(gray);
    return desc;
}