Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Vision tracking and camera server rectangle draws in only one spot (http://www.chiefdelphi.com/forums/showthread.php?t=154571)

rudun 01-02-2017 08:52

Vision tracking and camera server rectangle draws in only one spot
 
I am trying to draw a rectangle on the output based on the detected contours.
What i am getting is it works on initialization and then when you move the target, the rectangles are still in the same place. I am not sure where I am going wrong.

Code:

HttpCamera camera = CameraServer.getInstance().addAxisCamera("10.4.96.20");
                camera.setResolution(IMG_WIDTH, IMG_HEIGHT);
                pegVisionThread = new VisionThread(camera, new PegPipeline(), pipeline -> {
                       
                       
                        if (!pipeline.filterContoursOutput().isEmpty()) {
                               
                                synchronized (imgLock) {
                                        //centerX = r.x + (r.width / 2);
                                        //SmartDashboard.putNumber("center x", centerX);
                                        CvSink cvSink = CameraServer.getInstance().getVideo();
                                        CvSource outputStream = CameraServer.getInstance().putVideo("Peg Vision", 640, 480);

                                        Mat source = new Mat();
                                        //Mat output = new Mat();

                                        while (!Thread.interrupted()) {
                                                cvSink.grabFrame(source);
                                                Rect r = Imgproc.boundingRect(pipeline.filterContoursOutput().get(0));
                                                Rect r1 = Imgproc.boundingRect(pipeline.filterContoursOutput().get(1));
                                                Imgproc.rectangle(source, new Point(r.x, r.y), new Point(r.x + r.width, r.y + r.height),
                                                                new Scalar(0, 0, 255),2);
                                                Imgproc.rectangle(source, new Point(r1.x, r1.y), new Point(r1.x + r1.width, r1.y + r1.height),
                                                                new Scalar(0, 0, 255),2);
                                                //Imgproc.cvtColor(source, output, Imgproc.COLOR_BGR2GRAY);
                                                outputStream.putFrame(source);
                                                // Can do target math here

                                        }
                                }
                        }
                });
                pegVisionThread.setDaemon(true);
                pegVisionThread.start();


SamCarlberg 01-02-2017 11:20

Re: Vision tracking and camera server rectangle draws in only one spot
 
You have an infinite loop in the pipeline callback, so once the pipeline finds a contour, it will not run again.

rudun 01-02-2017 12:37

Re: Vision tracking and camera server rectangle draws in only one spot
 
Where is it getting caught? I assumed that in the while(!thread.interupted) would continue to grab a new frame and process as long the thread was running.


All times are GMT -5. The time now is 09:52.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi