首页 > 解决方案 > 我如何使用 OpenImaj 只听屏幕的两个特定区域

问题描述

我正在使用 OpenImaj 库来开发一个项目,该项目计算进出商场的人数:每次从上行到蓝线的一些动作都会计数一个数字。每次一些动作从下行传递到红线时,只需休息一个数字。

一点点画来更好地解释

在此处输入图像描述

我的项目中的线条非常好,但我无法设置聆听动作的区域。

我怎么能得到两个区域来识别从上到下正在发生一些运动,反之亦然。

package com.molokotech;
import org.openimaj.image.MBFImage;
import org.openimaj.image.colour.RGBColour;
import org.openimaj.math.geometry.point.Point2d;
import org.openimaj.math.geometry.point.Point2dImpl;
import org.openimaj.video.VideoDisplay;
import org.openimaj.video.VideoDisplayListener;
import org.openimaj.video.capture.VideoCapture;
import org.openimaj.video.capture.VideoCaptureException;

public class CounterInOut {
   public static void main(String[] args) throws VideoCaptureException {
      getVideoDisplayListener();
   }

private static void getVideoDisplayListener() throws VideoCaptureException {
    VideoCapture vc = new VideoCapture(320, 240);
    VideoDisplay<MBFImage> vd = VideoDisplay.createVideoDisplay(vc);

    vd.addVideoListener(
            new VideoDisplayListener<MBFImage>() {
                public void beforeUpdate(MBFImage frame) {
                   // frame.processInplace(new CannyEdgeDetector());
                    float separator = (frame.getWidth() * 0.05f);
                    // Line 1
                    Point2d p1 = new Point2dImpl((frame.getWidth() / 2 - separator), frame.getHeight() / 2);
                    Point2d p2 = new Point2dImpl(separator, frame.getHeight() / 2);
                    frame.drawLine(p1, p2, 3, RGBColour.BLUE);

                    // Line 2
                    Point2d p3 = new Point2dImpl((frame.getWidth() / 2 + separator), frame.getHeight() / 2);
                    Point2d p4 = new Point2dImpl(frame.getWidth() - separator, frame.getHeight() / 2);
                    frame.drawLine(p3, p4, 3, RGBColour.RED);
                }

                public void afterUpdate(VideoDisplay<MBFImage> display) {
                }
            });
    }

}

线条非常好,但现在没用。

在此处输入图像描述

首先我需要解决这个问题才能继续,因为我被卡住了。

是否有任何参数或东西来设置该区域以在此时拍摄事件 => vd.addVideoListener( ) { doSomething( ); };

像这样的东西:

vd.addVideoListener(coordinatesX, coordinatesY) { doSomething( ); };

库中不存在此代码,但我认为应该存在类似的代码。

所以我可以在两个方面调用它两次:

int actualCapacity = 0; 
vd.addVideoListener(0.0, 120.0) { actualCapacity++; };
vd.addVideoListener(160.0, 120.0) { actualCapacity--; };

只是伪代码。

标签: javavideo-processingopenimaj

解决方案


推荐阅读