本文整理汇总了Java中org.bytedeco.javacv.OpenCVFrameConverter类的典型用法代码示例。如果您正苦于以下问题:Java OpenCVFrameConverter类的具体用法?Java OpenCVFrameConverter怎么用?Java OpenCVFrameConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenCVFrameConverter类属于org.bytedeco.javacv包,在下文中一共展示了OpenCVFrameConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertCifar
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
/**
* Preprocess and store cifar based on successful Torch approach by Sergey Zagoruyko
* Reference: https://github.com/szagoruyko/cifar.torch
*/
public opencv_core.Mat convertCifar(Mat orgImage) {
numExamples++;
Mat resImage = new Mat();
OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat();
// ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2Luv);
// ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2Luv);
ImageTransform yuvTransform = new ColorConversionTransform(new Random(seed), COLOR_BGR2YCrCb);
ImageTransform histEqualization = new EqualizeHistTransform(new Random(seed), COLOR_BGR2YCrCb);
if (converter != null) {
ImageWritable writable = new ImageWritable(converter.convert(orgImage));
// TODO determine if need to normalize y before transform - opencv docs rec but currently doing after
writable = yuvTransform.transform(writable); // Converts to chrome color to help emphasize image objects
writable = histEqualization.transform(writable); // Normalizes values to further clarify object of interest
resImage = converter.convert(writable.getFrame());
}
return resImage;
}
示例2: 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) {
}
}
示例3: 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;
}
示例4: RandomCropTransform
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
public RandomCropTransform(Random random, long seed, int height, int width) {
super(random);
this.outputHeight = height;
this.outputWidth = width;
this.rng = Nd4j.getRandom();
this.rng.setSeed(seed);
this.converter = new OpenCVFrameConverter.ToMat();
}
示例5: LargestBlobCropTransform
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
/**
*
* @param random Object to use (or null for deterministic)
* @param mode Contour retrieval mode
* @param method Contour approximation method
* @param blurWidth Width of blurring kernel size
* @param blurHeight Height of blurring kernel size
* @param lowerThresh Lower threshold for either Canny or Threshold
* @param upperThresh Upper threshold for either Canny or Threshold
* @param isCanny Whether the edge detector is Canny or Threshold
*/
public LargestBlobCropTransform(Random random, int mode, int method, int blurWidth, int blurHeight, int lowerThresh,
int upperThresh, boolean isCanny) {
super(random);
this.rng = Nd4j.getRandom();
this.mode = mode;
this.method = method;
this.blurWidth = blurWidth;
this.blurHeight = blurHeight;
this.lowerThresh = lowerThresh;
this.upperThresh = upperThresh;
this.isCanny = isCanny;
this.converter = new OpenCVFrameConverter.ToMat();
}
示例6: WarpImageTransform
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
/**
* Constructs an instance of the ImageTransform.
*
* @param random object to use (or null for deterministic)
* @param dx1 maximum warping in x for the top-left corner (pixels)
* @param dy1 maximum warping in y for the top-left corner (pixels)
* @param dx2 maximum warping in x for the top-right corner (pixels)
* @param dy2 maximum warping in y for the top-right corner (pixels)
* @param dx3 maximum warping in x for the bottom-right corner (pixels)
* @param dy3 maximum warping in y for the bottom-right corner (pixels)
* @param dx4 maximum warping in x for the bottom-left corner (pixels)
* @param dy4 maximum warping in y for the bottom-left corner (pixels)
*/
public WarpImageTransform(Random random, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3,
float dx4, float dy4) {
super(random);
deltas = new float[8];
deltas[0] = dx1;
deltas[1] = dy1;
deltas[2] = dx2;
deltas[3] = dy2;
deltas[4] = dx3;
deltas[5] = dy3;
deltas[6] = dx4;
deltas[7] = dy4;
this.converter = new OpenCVFrameConverter.ToMat();
}
示例7: ResizeImageTransform
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
/**
* Returns new ResizeImageTransform object
*
* @param random Random
* @param newWidth new Width for the outcome images
* @param newHeight new Height for outcome images
*/
public ResizeImageTransform(Random random, int newWidth, int newHeight) {
super(random);
this.newWidth = newWidth;
this.newHeight = newHeight;
this.converter = new OpenCVFrameConverter.ToMat();
}
示例8: makeRandomBufferedImage
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
BufferedImage makeRandomBufferedImage(int height, int width, int channels) {
Mat img = makeRandomImage(height, width, channels);
OpenCVFrameConverter.ToMat c = new OpenCVFrameConverter.ToMat();
Java2DFrameConverter c2 = new Java2DFrameConverter();
return c2.convert(c.convert(img));
}
示例9: run
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
@Override
protected void run() throws GrabberServiceException {
final OpenCVFrameConverter.ToMat convertToMat = new OpenCVFrameConverter.ToMat();
final Stopwatch stopwatch = Stopwatch.createStarted();
while (super.isRunning()) {
runOneGrab(convertToMat, stopwatch);
}
}
示例10: runOneGrab
import org.bytedeco.javacv.OpenCVFrameConverter; //导入依赖的package包/类
@VisibleForTesting
final void runOneGrab(final OpenCVFrameConverter.ToMat convertToMat, final Stopwatch stopwatch)
throws GrabberServiceException {
final Frame videoFrame;
try {
videoFrame = frameGrabber.grab();
} catch (FrameGrabber.Exception ex) {
throw new GrabberServiceException("Failed to grab image", ex);
}
final opencv_core.Mat frameMat = convertToMat.convert(videoFrame);
if (frameMat == null || frameMat.isNull()) {
throw new GrabberServiceException("Returned a null frame Mat");
}
if (frameMat.empty()) {
throw new GrabberServiceException("Returned an empty Mat");
}
updater.copyNewMat(frameMat);
stopwatch.stop();
final long elapsedTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
stopwatch.reset();
stopwatch.start();
if (elapsedTime != 0) {
updater.setFrameRate(IntMath.divide(1000, Math.toIntExact(elapsedTime), RoundingMode.DOWN));
}
updater.updatesComplete();
exceptionClearedCallback.run();
}
示例11: 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));
}
示例12: 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);
}
示例13: 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));
}
示例14: 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);
}
示例15: 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));
}
}