B4J Question JavaCV with camera

bjfhs

Active Member
Licensed User
When I use java inline(javacv) to open camera,I can't get any thing.Can you give me any advice ?
B4X:
NativeMe.RunMethod("showVideo",Null)
B4X:
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)
    {
    }
 }
 

bjfhs

Active Member
Licensed User
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

Daestrum

Expert
Licensed User
Longtime User
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

bjfhs

Active Member
Licensed User
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

  • test.zip
    420.7 KB · Views: 183
Upvote 0
Top