B4J Question JavaCV with camera

bjfhs

Active Member
Licensed User
Longtime User
When I use java inline(javacv) to open camera,I can't get any thing.Can you give me any advice ?
Code: Copy
NativeMe.RunMethod("showVideo",Null)
Code: Copy
public static void showVideo() {
   OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0); 
    try{
    grabber.start();  
    CanvasFrame canvas = new CanvasFrame("camera");
    canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    canvas.setAlwaysOnTop(true);
   
    while(true)
    {
        if(!canvas.isDisplayable())
        {
            grabber.stop();
            System.exit(2);
        }
        canvas.showImage(grabber.grab());
       
        Thread.sleep(500);
    }
    }
    catch (Exception e)
    {
    }
 }
 
The code is ok,my camera is bad.
But I find a new question,when the video is show,the main window can't do any thing,why?
 
Upvote 0
It sounds like it is running on the main thread and not allowing the ui to update.

You probably need to run the routine on either
a, a different thread to the main program
b, Use Application.RunLater to run it.
 
Upvote 0
It sounds like it is running on the main thread and not allowing the ui to update.

You probably need to run the routine on either
a, a different thread to the main program
b, Use Application.RunLater to run it.
You are right.but I don't know how to start a new thread in B4J(or java inline) and how to use Application.RunLater to run it.
Can you help me?
All the code in the attached file.
 

Attachments

Upvote 0
Back
Top