Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i can't read video stream from ip camera

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 3 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

i can't read video stream from ip camera

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 3 errors: - 7 errors:

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

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

  • libpng warning: Image width is zero in IHDR - IHDR
  • libpng warning: Image height is zero in IHDR - IHDR
  • libpng error: Invalid IHDR data - 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

i can't read video stream from ip camera

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.capture.release();
        // clean the frame
        this.originalFrame.setImage(null);
    }

}
private void detectAndDisplay(Mat fr ){
    faces = new MatOfRect();
    //Mat grayFrame = new Mat();
    frame =fr;
    try{
    // convert the frame in gray scale
    Imgproc.cvtColor(frame, grayFrame, Imgproc.COLOR_BGR2GRAY);
    // equalize the frame histogram to improve the result
    Imgproc.equalizeHist(grayFrame, grayFrame);

    // compute minimum face size (20% of the frame height, in our case)
    if (this.absoluteFaceSize == 0){
        int height = grayFrame.rows();
        if (Math.round(height * 0.2f) > 0)
        {
            this.absoluteFaceSize = Math.round(height * 0.2f);
        }
    }

    // detect faces
    this.faceCascade.detectMultiScale(grayFrame, faces, 1.1, 2, 0 | Objdetect.CASCADE_SCALE_IMAGE,
            new Size(this.absoluteFaceSize, this.absoluteFaceSize), new Size());
    // each rectangle in faces is a face: draw them!
    facesArray = faces.toArray();
    double xTl1, yTl1,xTl2,yTl2,x,y;
    for (int i = 0; i < facesArray.length; i++){
        Imgproc.rectangle(frame, facesArray[i].tl(), facesArray[i].br(), new Scalar(255, 255, 0), 3);
        //System.out.println(facesArray[i].tl() + "  "+ facesArray[i].br());                    
         xTl1=facesArray[0].tl().x;
         yTl1 =facesArray[0].tl().y;
         xBr2=facesArray[0].br().x;
         yBr2=facesArray[0].br().y;
         x=(xTl2-xTl1)/2;
         y=(yBr1-yBR2)/2;
        centerFace(x,y);
        }
    }catch(Exception e){
        System.err.println(e.getMessage());
    }
}