开发者

java opencv application thread problem

I'm developing a sort of simple antitheft java application as university project. It records the scene through the camera and detects when many changes in the scene occurs by making pixel difference (you can see the full sources here: https://github.com/lmammino/movementDetector). I'm using opencv java bindings to handle the various operations i need to perform on images.

I have some problems couse I want the user to start/stop/restart the video capturing process by using some buttons in the main user interface.

To capture the video stream I use the java opencv 开发者_StackOverflow中文版provided classes CanvasFrame and OpenCVFrameGrabber. I have a deveoped a Runnable class called Detector (full source here: http://bit.ly/l1Z3tY)

The Detector class automatically runs a new Thread of itself by calling its start method:

public void start()
{
    if (this.thread == null)
        this.thread = new Thread(this);

    this.isThreadActive = true;
    this.thread.start();
}

The first time i call the start method from a Detector instance everything works fine. When i try to stop and restart the process it gives invalid thread state exception...

So i think the whole question here it's: "what's the best way to start/stop/restart a thread?"

TNX


Is the object you are stopping/restarting actually a Runnable, or is it a Thread? If I recall correctly, you can only run a thread once. If you want to run it more than once, you need to run the Runnable multiple times, not the Thread.

From the Thread documentation: It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜