在 OpenCV 中,我有一个绝妙的想法,即以 720p 从相机捕获视频,但在处理之前将其下采样至 480p。这样我得到更快的处理,但保持高清输出图像。
[1] cap.read(hd) <-- 80ms
[2] Imgproce.resize(hd,sd)
[3] BackgroundSubtractorMOG.apply(sd) <-- 20ms
^ takes 100ms
这是奇怪的事情。无论我是否下采样,这条链都需要相同的时间。如果我删除下采样,我会得到:
[1] cap.read(hd) <--- 20ms
[2] BackgroundSubtractorMOG.apply(hd) <-- 80ms
^ also takes 100ms
我很困惑。为什么阅读时间取决于我以后做什么!?
编辑:根据要求,一些真实的代码:
BackgroundSubtractorMOG mog = new BackgroundSubtractorMOG();
Mat captured = new Mat();
Mat foreground = new Mat();
Mat downsampled = new Mat();
while (true) {
long MEASURE_all = System.nanoTime();
vc.read(captured);
long MEASURE_resize = System.nanoTime();
Imgproc.resize(captured, downsampled,
new org.opencv.core.Size(processing_width, processing_height));
long MEASURE_foreground = System.nanoTime();
mog.apply(downsampled, foreground, -1);
long MEASURE_draw = System.nanoTime();
// some more stuff
System.out.println("retrieve: " + ((MEASURE_resize) - MEASURE_all)/1000000 +
", resize: " + ((MEASURE_foreground) - MEASURE_resize)/1000000 // ...
}