本文整理汇总了Java中org.bytedeco.javacv.FrameGrabber.Exception方法的典型用法代码示例。如果您正苦于以下问题:Java FrameGrabber.Exception方法的具体用法?Java FrameGrabber.Exception怎么用?Java FrameGrabber.Exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bytedeco.javacv.FrameGrabber
的用法示例。
在下文中一共展示了FrameGrabber.Exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFrame
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
/**
* Sets the frame grabber to the given frame number. This will pause frame grabber from reading
* successive frames; it can be resumed with {@link #resume()}. This runs asynchronously and
* will complete at some point in the future after this method is called.
*
* @param frameNumber the number of the frame to grab
*
* @throws IllegalArgumentException if {@code frameNumber} is negative or exceeds the number of
* frames in the video file
*/
public void setFrame(int frameNumber) {
if (frameNumber < 0) {
throw new IllegalArgumentException("Negative frame number " + frameNumber);
}
if (frameNumber > frameGrabber.getLengthInFrames()) {
throw new IllegalArgumentException(
"Frame number too high: " + frameNumber + " > " + frameGrabber.getLengthInFrames());
}
pause();
try {
frameGrabber.setFrameNumber(frameNumber);
} catch (FrameGrabber.Exception e) {
getExceptionWitness().flagException(e, "Could not set frame number");
}
manualGrabberService.submit(this::grabNextFrame);
}
示例2: grabDepth
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void grabDepth() {
try {
depthCamera.currentImage = grabber.grabDepth();
((WithTouchInput) depthCamera).newTouchImageWithColor(colorCamera.currentImage);
} catch (FrameGrabber.Exception ex) {
Logger.getLogger(CameraOpenKinect.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: grabColor
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void grabColor() {
try {
colorCamera.updateCurrentImage(grabber.grabVideo());
} catch (FrameGrabber.Exception ex) {
Logger.getLogger(CameraOpenKinect.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: initialize
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void initialize() throws IOException {
try {
frameGrabber = new FFmpegFrameGrabber(path);
frameGrabber.start();
final double fps = frameGrabber.getFrameRate();
fpsSocket.setValue(fps);
frameCount = frameGrabber.getLengthInFrames();
if (frameCount <= 1) {
// Only one frame, no point in scheduling automatic updates to grab the same
// image over and over
manualGrabberService.submit(this::grabNextFrame);
} else {
grabberFuture = Executors.newSingleThreadScheduledExecutor(DaemonThread::new)
.scheduleAtFixedRate(
() -> {
if (!isPaused()) {
grabNextFrame();
}
},
0L,
(long) (1e3 / fps),
TimeUnit.MILLISECONDS
);
}
} catch (FrameGrabber.Exception e) {
throw new IOException("Could not open video file " + path, e);
}
}
示例5: grabNextFrame
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
/**
* Grabs the next frame from the video, or the first frame
* if the end of the file has been reached.
*/
private void grabNextFrame() {
try {
Frame frame = frameGrabber.grabFrame();
if (frame == null) {
// End of the video file, loop back to the first frame
frameGrabber.setFrameNumber(0);
grabNextFrame();
return;
}
Mat m = converter.convert(frame);
if (m == null) {
// Try again (I have no idea why this happens)
grabNextFrame();
return;
}
synchronized (workingMat) {
m.copyTo(workingMat);
}
m.release();
currentFrame.set(frameGrabber.getFrameNumber()); // best guess
isNewFrame.set(true);
eventBus.post(new SourceHasPendingUpdateEvent(this));
} catch (FrameGrabber.Exception e) {
getExceptionWitness().flagException(e);
}
}
示例6: onSourceRemoved
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Subscribe
public void onSourceRemoved(SourceRemovedEvent sourceRemovedEvent) {
if (sourceRemovedEvent.getSource() == this) {
try {
if (grabberFuture != null && !grabberFuture.isCancelled()) {
grabberFuture.cancel(true);
}
frameGrabber.stop();
} catch (FrameGrabber.Exception e) {
getExceptionWitness().flagException(e, "Exception when stopping frame grabber");
} finally {
eventBus.unregister(this);
}
}
}
示例7: startUp
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
protected void startUp() throws GrabberServiceException {
serviceThread = Optional.of(Thread.currentThread());
try {
frameGrabber = frameGrabberSupplier.get();
frameGrabber.start();
} catch (FrameGrabber.Exception ex) {
throw new GrabberServiceException("Failed to start", ex);
}
}
示例8: runOneGrab
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的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();
}
示例9: shutDown
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
protected void shutDown() throws GrabberServiceException {
updater.setFrameRate(0);
updater.updatesComplete();
try {
frameGrabber.stop();
} catch (FrameGrabber.Exception ex) {
throw new GrabberServiceException("Failed to stop", ex);
}
}
示例10: nextTuple
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void nextTuple() {
long now = System.currentTimeMillis();
if (now - lastFrameTime < delayInMS) {
return;
} else {
lastFrameTime = now;
}
if (frameId < endFrameID) {
try {
long start = System.currentTimeMillis();
image = grabber.grab();
mat = new opencv_core.Mat(image);
opencv_core.Mat matNew = new opencv_core.Mat();
opencv_core.Size size = new opencv_core.Size(W, H);
opencv_imgproc.resize(mat, matNew, size);
Serializable.Mat sMat = new Serializable.Mat(matNew);
collector.emit(RAW_FRAME_STREAM, new Values(frameId, sMat), frameId);
if (frameId % sampleFrames == 0) {
collector.emit(SAMPLE_FRAME_STREAM, new Values(frameId, sMat, sampleID), frameId);
sampleID ++;
}
long nowTime = System.currentTimeMillis();
System.out.printf("Sendout: " + nowTime + "," + frameId + ",used: " + (nowTime -start));
frameId++;
} catch (FrameGrabber.Exception e) {
e.printStackTrace();
}
}
}
示例11: Jmcv
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
public Jmcv() {
try {
classifier = new CvHaarClassifierCascade(cvLoad(getClass().getClassLoader().
getResource(CascadeName.CASCADE_FRONTALFACE_ALT2).getPath()));
if (classifier.isNull()) {
System.err.println("Error loading classifier file: " +
getClass().getClassLoader().
getResource(CascadeName.CASCADE_FRONTALFACE_ALT2).getPath());
System.exit(1);
}
storage = CvMemStorage.create();
try {
// try camera 0
grabber = FrameGrabber.createDefault(0);
grabber.start();
iplImage = grabber.grab();
} catch (FrameGrabber.Exception exception) {
// if camera 0 fails, try camera 1
grabber = FrameGrabber.createDefault(1);
grabber.start();
iplImage = grabber.grab();
}
grayImage = IplImage.create(iplImage.width(), iplImage.height(), IPL_DEPTH_8U, 1);
detectionArea = new Dimension();
detectionPoint = new Dimension();
} catch (FrameGrabber.Exception ex) {
Logger.getLogger(Jmcv.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例12: track
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
/**
* Read a video from a URL, and perform pedestrian tracking on it.
*
* @param videoStream the video stream to conduct tracking on.
* @return a set of tracklets of pedestrians.
*/
@Nonnull
@Override
public Tracklet[] track(@Nonnull InputStream videoStream) throws FrameGrabber.Exception {
FFmpegFrameGrabber frameGrabber = new FFmpegFrameGrabber(videoStream);
av_log_set_level(AV_LOG_QUIET);
frameGrabber.start();
logger.debug("Initialized video decoder!");
long trackerPointer = initialize(frameGrabber.getImageWidth(), frameGrabber.getImageHeight(), 3, conf);
logger.debug("Initialized tracker!");
int cnt = 0;
// Every time a frame is retrieved during decoding, it is immediately fed into the tracker,
// so as to save runtime memory.
while (true) {
Frame frame;
try {
frame = frameGrabber.grabImage();
} catch (FrameGrabber.Exception e) {
logger.error("On grabImage: " + e);
break;
}
if (frame == null) {
break;
}
final byte[] buf = new byte[frame.imageHeight * frame.imageWidth * frame.imageChannels];
final opencv_core.Mat cvFrame = new OpenCVFrameConverter.ToMat().convert(frame);
cvFrame.data().get(buf);
int ret = feedFrame(trackerPointer, buf);
if (ret != 0) {
break;
}
++cnt;
if (cnt % 1000 == 0) {
logger.debug("Tracked " + cnt + " frames!");
}
}
logger.debug("Totally processed " + cnt + " framed!");
logger.debug("Getting targets...");
Tracklet[] targets = getTargets(trackerPointer);
logger.debug("Got " + targets.length + " targets!");
free(trackerPointer);
for (int i = 0; i < targets.length; ++i) {
targets[i].numTracklets = targets.length;
targets[i].id.serialNumber = i;
}
return targets;
}
示例13: internalStart
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void internalStart() throws FrameGrabber.Exception {
grabber.start();
}
示例14: testEnsureThatGrabberIsReinitializedWhenStartThrowsException
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Test
public void testEnsureThatGrabberIsReinitializedWhenStartThrowsException() throws IOException,
TimeoutException {
final String GRABBER_START_MESSAGE = "This is expected to fail this way";
Waiter waiter1 = new Waiter();
Waiter waiter2 = new Waiter();
Waiter waiter3 = new Waiter();
Queue<Waiter> waiterQueue = new LinkedList<>(Arrays.asList(waiter1, waiter2, waiter3));
CameraSource source = new CameraSource(new EventBus(), osf, new CameraSource
.FrameGrabberFactory() {
@Override
public FrameGrabber create(int deviceNumber) {
return new SimpleMockFrameGrabber() {
@Override
public void start() throws Exception {
if (!waiterQueue.isEmpty()) {
waiterQueue.poll().resume();
}
throw new FrameGrabber.Exception(GRABBER_START_MESSAGE);
}
};
}
@Override
public FrameGrabber create(String addressProperty) throws MalformedURLException {
throw new AssertionError("This should not be called");
}
}, MockExceptionWitness.MOCK_FACTORY, 0);
Waiter failedWaiter = new Waiter();
source.addListener(new Service.Listener() {
@Override
public void failed(Service.State from, Throwable failure) {
failedWaiter.assertNotNull(failure);
failedWaiter.assertNotNull(failure.getCause());
failedWaiter.assertEquals(GRABBER_START_MESSAGE, failure.getCause().getMessage());
failedWaiter.resume();
}
}, MoreExecutors.directExecutor());
source.startAsync();
waiter1.await();
waiter2.await();
waiter3.await();
source.stopAndAwait();
failedWaiter.await();
}
示例15: start
import org.bytedeco.javacv.FrameGrabber; //导入方法依赖的package包/类
@Override
public void start() throws Exception {
if (shouldThrowAtStart) {
throw new FrameGrabber.Exception("Throwing on start was enabled!");
}
}