i can't read video stream from ip camera [closed]

asked 2017-03-27 03:48:09 -0500

DrMessina gravatar image

updated 2017-03-27 04:27:06 -0500

when i start the ccamera it goes well. the problem comes when i release the video capture and try to open it after. it shows me 7 errors:

  • [mpjpeg @ 000000000041c280] Expected boundary '--' not found, instead found a line of 86 bytes
  • [mjpeg @ 00000000004274a0] error dc

  • [mjpeg @ 00000000004274a0] error y=21 x=34

  • libpng warning: Image width is zero in IHDR
  • libpng warning: Image height is zero in IHDR
  • libpng error: Invalid IHDR data
  • error: (-215) code in function cv::imencode

i don't understand why when i close the whole program and relaunched it the reading works but it crash with the same error when try to release and reopen the videocapture

this is a part of the code:

protected void init() {

    this.capture = new VideoCapture();
    Vector<?> objs = getSerialPortNames();
    portName =(String) objs.firstElement();
    System.out.println( portName);

    this.faceCascade = new CascadeClassifier();
    this.absoluteFaceSize = 0;
    connect();
    writeOnPort("0");
}
@FXML
protected void startCamera()
{

    // set a fixed width for the frame
    originalFrame.setFitWidth(600);
    // preserve image ratio
    originalFrame.setPreserveRatio(true);

    if (!this.cameraActive)
    {
        // disable setting checkboxes
        this.haarClassifier.setDisable(true);
        this.lbpClassifier.setDisable(true);
        this.pictureButton.setDisable(false);
        this.cropButton.setDisable(false);
        this.compare.setDisable(false);
        // start the video capture

        this.capture.open(0);
        //this.capture.open(url);   
        /*capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 720);
        capture.set(Videoio.CAP_PROP_FRAME_WIDTH, 480);*/

        // is the video stream available?
        if (this.capture.isOpened())
        {
            this.cameraActive = true;
            //activate servos every 1000ms
            Runnable action = new Runnable(){ 
                //private ScheduledExecutorService timers;
                @Override
                public void run() {
                    System.out.println(faces);                      
                    if(faces == null) return;

                    if(faces.dataAddr()== 0x0){
                        if(run != true){
                            System.out.println("0x0");
                            //faceDetected = false;
                            writeOnPort("0");
                            //try {output.flush();} catch (IOException e) {e.printStackTrace();}
                            System.out.println( " looking for your faces!! ");
                            stopped =false;
                            run=true;
                            //(new Thread(new SerialReader(input))).start();
                        }                           
                    }else{
                        if(stopped != true){
                            System.out.println("faces");

                            //faceDetected = true;
                            writeOnPort("1");
                            //try {output.flush();} catch (IOException e) {e.printStackTrace();}
                            System.out.println( "stop");
                            run = false;
                            stopped=true;
                            //(new Thread(new SerialReader(input))).start();
                        }
                        //if(!run) System.out.println( "crop face");
                        //cropFace();
                        //if(!run) System.out.println( "test face");
                        //testFace();
                        //if(!run) System.out.println( "loop done");
                    }
                }
            };
            // grab a frame every 33 ms (30 frames/sec)*/
            Runnable frameGrabber = new Runnable() {                    
                @Override
                public void run()
                {
                    Image imageToShow = grabFrame();
                    originalFrame.setImage(imageToShow);
                }
            };
            this.timer = Executors.newSingleThreadScheduledExecutor();
            this.timer.scheduleAtFixedRate(frameGrabber, 0, 33, TimeUnit.MILLISECONDS);             

            this.timer = Executors.newSingleThreadScheduledExecutor();
            this.timer.scheduleWithFixedDelay(action, 0, 800, TimeUnit.MILLISECONDS);
            // update the button content
            this.cameraButton.setText("Stop Camera");
        }
        else
        {
            // log the error
            System.err.println("Failed to open the camera connection...");
        }
    }
    else
    {
        // the camera is not active at this point
        this.cameraActive = false;
        // update again the button content
        this.cameraButton.setText("Start Camera");
        // enable classifiers checkboxes
        this.haarClassifier.setDisable(false);
        this.lbpClassifier.setDisable(false);
        this.pictureButton.setDisable(true);
        this.cropButton.setDisable(true);
        this.compare.setDisable(true);
        // stop the timer

        try
        {
            this.timer.shutdown();
            this.timer.awaitTermination(33, TimeUnit.MILLISECONDS);
        }
        catch (InterruptedException e)
        {
            // log the exception
            System.err.println("Exception in stopping the frame capture, trying to release the camera now... " + e);
        }

        // release the camera
        this ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by DrMessina
close date 2017-04-04 03:32:44.443771

Comments

can we see your code ?

berak gravatar imageberak ( 2017-03-27 03:53:26 -0500 )edit

it's quite lenghty but i show u some part

DrMessina gravatar imageDrMessina ( 2017-03-27 04:21:59 -0500 )edit

dont worry about the center face function it's just about trigonometrical calculation to move servos

DrMessina gravatar imageDrMessina ( 2017-03-27 04:30:02 -0500 )edit

i try using another camera my code works well so this is related to ip camera; i'm using an AXIS M1054 and i can't find out why it work with the camera in my computer and not with the ip one.

DrMessina gravatar imageDrMessina ( 2017-03-27 06:35:30 -0500 )edit

the problem was coming from the fact that axis camera cant be release so if some one have this probleme just open the videocapture but don't close it if u have an ip camera.

DrMessina gravatar imageDrMessina ( 2017-04-04 03:34:24 -0500 )edit