opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.95k stars 55.62k forks source link

Issues with recognition whilst using IP Stream only #8188

Closed AdamMiltonBarker closed 6 years ago

AdamMiltonBarker commented 7 years ago
System information (version)
Detailed description

I will try ask in here as got no response on the forum. I have been working with OpenCV in an application since last year. The first version I was capturing the frame from a webcam and using Haarcascades and without an issue it would recognise a face nearly every time.

I came into some issues with getting a stable web based stream going, after trying multiple solutions I moved to a new way. This is still using the exact same webcam except Linux Motion is accessing it and OpenCV is now connecting to the mjpeg stream from Linux Motion through a secure Nginx server, the stream is on the same device as the OpenCV script.

Since doing this the quality of the stream has increased massively, but, it now no longer detects faces, at all hardly, I have compared screen shots of frames from when OpenCV was accessing the webcam and frames from when OpenCV is accessing the stream, and apart from the improved quality of the frames there really is not any difference, yet OpenCV refuses to identify a face, it is literally a case where I have to move the camera around and hold a position to identify a face, before I could be walking past on the other side of the room and it would detect my face.

After trying everything i could think of and find on Google, I went back to the webcam, instantly it was detecting my face in whatever position, in what ever light. I have tried multiple other ways of streaming to the web again but still not successful so have moved back to the Motion stream again to try work this out.

Can anyone shed any light on this, it does not make sense to me that an improvement in quality suddenly breaks facial identification. I have tried playing with the frame settings, resolution, contrast, hue, brightness and nothing I can do seems to work.

Steps to reproduce
self.OpenCVCapture.open('http://MOTION_STREAM_ADDRESS/stream.mjpg')
self.OpenCVCapture.set(5, 30) 
self.OpenCVCapture.set(3,1280)
self.OpenCVCapture.set(4,720)
self.OpenCVCapture.set(10,1)

Then run through Haarcascades for detection.

StevenPuttemans commented 7 years ago

Hi @AdamMiltonBarker without a sample video of your data, it is kind of impossible to see/test what is going wrong. That being said

So please either provide a video of your stream (as less compression as possible) or provide a open access link to your current mjpeg stream so we can reproduce the issue.

AdamMiltonBarker commented 7 years ago

OK thanks will look at OpenCV 3.2. Can you give me an email or something, I am not going to post my stream URL here :) But will definitely send it you privately so you can see in realtime what is going on.

StevenPuttemans commented 7 years ago

You can send it to steven(dot)puttemans(at)kuleuven(dot)be.

Op 12 feb. 2017 4:14 p.m. schreef AdamMiltonBarker notifications@github.com:

OK thanks will look at OpenCV 3.2. Can you give me an email or something, I am not going to post my stream URL here :) But will definitely send it you privately so you can see in realtime what is going on.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/opencv/opencv/issues/8188#issuecomment-279224861, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AEaDt3Dqoqb-Sfr2lZwG0wxwVflGn4sIks5rbyGvgaJpZM4L-ccr.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/opencv/opencv","title":"opencv/opencv","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/opencv/opencv"}},"updates":{"snippets":[{"icon":"PERSON","message":"@AdamMiltonBarker in #8188: OK thanks will look at OpenCV 3.2. Can you give me an email or something, I am not going to post my stream URL here :) But will definitely send it you privately so you can see in realtime what is going on. "}],"action":{"name":"View Issue","url":"https://github.com/opencv/opencv/issues/8188#issuecomment-279224861" }}}

AdamMiltonBarker commented 7 years ago

@StevenPuttemans I have uploaded the full current code to the repo plus all steps taken documented, you can view it here, results are still the same, any help would be great.

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/tree/master/Computer-Vision/Python

StevenPuttemans commented 7 years ago

Just did a test code in C++, running

#include <iostream>
#include "opencv2/opencv.hpp"

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cap("https://xxxxx//stream.mjpg");
    CascadeClassifier model("/data/face.xml"); // the newest face model
    Mat frame;

    while(true){
        cap >> frame;
        Mat temp;
        resize(frame, temp, Size(frame.cols/2, frame.rows/2));
        vector<Rect> detections;
        model.detectMultiScale(temp, detections, 1.1, 3);
        cerr << "Detections found = " << detections.size() << endl;
        for(int i=0; i < detections.size(); i++){
            rectangle(temp, detections[i], Scalar(255,255,0), 3);
        }
        imshow("test", temp); waitKey(1);
    }
    return 0;
}

and it generated this result: https://vid.me/L17v (result oploading as we speak)

So it is working, but keep in mind that OpenCV face detectors are in principle frontal face detectors!

AdamMiltonBarker commented 7 years ago

Hi thanks it definitely is not working as expected. I get about the frontal face detectors, I run it through 4 haarcascades, as mentioned this works fine when accessing the frames directly from webcam. I have been sat here all day watching the results and whereas before it used to detect say 75 / 100 times it is not detecting about 5 - 10 / 100.

AdamMiltonBarker commented 7 years ago

Did you check the Python code I linked to mate? I cannot speak for C++ but my application is terrible compared to what it used to be running from the webcam.

StevenPuttemans commented 7 years ago

But it is .. if I run my code, every single time you look at the cam it detects you. For the moment the angle is wrong. I can prove this to you if you move the camera in relation to the stream...

StevenPuttemans commented 7 years ago

I do not have a Python setup available, but since Python are simple wrappers around C++ that should be identical.

AdamMiltonBarker commented 7 years ago

Sorry but it is not. If I switch to the webcam stream, moving or changing nothing else, it immediately detects my face every few seconds - at different angles, at the moment I am lucky if it does 1 in a minute or 2, better results when the two screens in front of me are bright white and the background light gets over powered, no results almost when the screens are darker. But 100% it is not working correctly.

RE the angle, as mentioned above mate, if I switch to the webcam stream it works fine, as it is now it is not. I do not need to change the angle of the camera for good results when hitting the webcam stream directly, I have been testing this for days. Even if I do have the angle spot I still have the same results.

Other information if using the webcam stream it can detect me on the other side of the room, at the moment it will not.

I now have the camera facing straight at me:

Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s)

And so on, with the computer screen white after about 5 minutes it begins to detect occassionaly so there is some sort of delay now. Changing back to a dark screen it will no longer detect, none of this happens when accessing the camera directly.

AdamMiltonBarker commented 7 years ago

Could you have a look at these two files please, you may not be able to replicate this as you are not using the code I am using.

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/TASS.py

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/TASSCore.py

StevenPuttemans commented 7 years ago

1) The face detector part needs a frontal view, because it depends on those specific features. I just watched you for 5 minutes and about 60% of the time, from the moment you look towards the camera more, you get detected by my code.

2) that being said, I have the impression from code part 2, you are using some outdated code. Use the latest version possible.

StevenPuttemans commented 7 years ago

Oh and btw, if you are not using OpenCV 3.2, or OpenCV 2.4.13 from the python wrappers, then face detection and recognition will never work decently. They have been broke times and times over but finally reached a fixed and stable form now.

Also you just went darker, just works fine here ...

StevenPuttemans commented 7 years ago

Will upload vid cause that service does not seem to work! Just a sec!

StevenPuttemans commented 7 years ago

https://youtu.be/wqdK4-bxu7U there you go

AdamMiltonBarker commented 7 years ago

Ok thanks for help.

As it went dark just as you said:

Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s)

RE your comments above:

  1. This is not the case with my program when using the web cam stream, it works perfectly fine, only issue is now using the ip stream. (And has done for a very very long time)

  2. Ok could you link me to the docs please. and which part is outdated ?

  3. Here is the configs. https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/config.json

I will upgrade to 3.2 now could you show me to the docs please mate.

All being said, none of the above suggests why it works perfectly fine without issues on the webcam direct stream and not on the IP stream, if it really was not happening, and it really was working the same on the webcam stream, I would not of spent the last few days bashing my head against the wall trying to solve it lol.

I dont know what more to say, here, it is hardly ever detecting me, especially not from over the other side of the room, I am sat here now and it has not detected my face when I am right in front of the camera for about 5 minutes, switching back to the webcam direct frames, it pics me up in all scenarios, nearly every seconds

Right now, this is my log

Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s)

StevenPuttemans commented 7 years ago

Wait be fair, as it goes dark, your camera is adjusting to lesser light, but from the moment that works, the detections are back. That is normal in my opinion. Keep in mind that the training data for the detector are all clear well illuminated faces.

The video I show you is run directly on your stream, but it is exactly the same as reading from a file or webcam directly using exactly the same interface...

Look at my command above for detection, you do not need anything else then those parameters. All the other flags are leftovers of an old and forgotton C - interface of OpenCV...

DOCS: http://docs.opencv.org/ then pick your version.

All being said, none of the above suggests why it works perfectly fine without issues on the webcam direct stream and not on the IP stream, if it really was not happening, and it really was working the same on the webcam stream, I would not of spent the last few days bashing my head against the wall trying to solve it lol.

Agreed, but watch the video and notice that it works just fine on a stream in C++ right. Only possible issue if updating does not work is a fault in the wrapper for python.

AdamMiltonBarker commented 7 years ago

One sec I restarted it.

Even with the screens fully white this is the output:

Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2727 Published to Device Sensors Channel Published: 2728 Published to Device Warnings Channel Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2729 Published to Device Sensors Channel Published: 2730 Published to Device Warnings Channel Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published: 2731 Published to Device Warnings Channel Published: 2732 Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2733 Published to Device Sensors Channel Published: 2734 Published to Device Warnings Channel Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2735 Published: 2736 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2737 Published: 2738 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2739 Published: 2740 Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2741 Published: 2742 Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2743 Published to Device Sensors Channel Published: 2744 Published to Device Warnings Channel Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2745 Published: 2746 Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published: 2747 Published to Device Warnings Channel Published: 2748 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2749 Published to Device Sensors Channel Published: 2750 Published to Device Warnings Channel Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2751 Published: 2752 Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2753 Published: 2754 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2755 Published: 2756 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2757 Published: 2758 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2759 Published: 2760 Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2761 Published: 2762 Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published to Device Sensors Channel Published to Device Warnings Channel Published: 2763 Published: 2764 Found 1 face(s) Person not recognised 0 Confidence 1.7976931348623157e+308 Published: 2765 Published to Device Sensors Channel Published: 2766 Published to Device Warnings Channel Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) ^[Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s) Found 0 face(s)

In comparison to the webcam this is really terrible which is why I have hardly slept for days trying to resolve this. Using direct access to the webcam it is literally every second it is detecting, when I turn off the bright screen it will not detect me at all.

AdamMiltonBarker commented 7 years ago

Hi @StevenPuttemans, I have started again with a fresh install of Jessie and installed the latest OpenCV will get back to once all set up.

I made a tutorial about installing OpenCV 3.2.0 on a Raspberry Pi if it is any use to you.

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/2-Installing-OpenCV-3-2-0.md

AdamMiltonBarker commented 7 years ago

@StevenEWright after upgrading it does nothing it just hangs, I have removed the frame rate etc in TASS.py, downloaded and replaced the frontal xml file with one you supplied, removed flags=cv2.CASCADE_SCALE_IMAGE from TASSCore.py, now it just stays in the loop, no activity whatever.

TASS.OpenCVCapture.read() is returning null every time.

AdamMiltonBarker commented 7 years ago

If I change to the webcam feed directly, it does return something but I get the following:


Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd1
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 5 extraneous bytes before marker 0xd7
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd0
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd1
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 3 extraneous bytes before marker 0xd7
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 3 extraneous bytes before marker 0xd0
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 4 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd1
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd7
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 6 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd6
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 3 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 4 extraneous bytes before marker 0xd5
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 2 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd2
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd4
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd0
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

Corrupt JPEG data: 1 extraneous bytes before marker 0xd3
IN DETECT
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage
StevenPuttemans commented 7 years ago

/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

This should mean that somewhere you are opening or closing a file it cannot access. Can you try absolute paths everywhere first?

AdamMiltonBarker commented 7 years ago

Hi thanks for the reply. I am opening and closing no files other than the haarcascades in that function and they have always had absolute paths:

Printing out the path used for one of the haarcascades: /home/ds62hdsa/IoT-JumpWay-RPI-Examples/Computer-Vision/Python/Haarcascades/lbpcascade_frontalface_improved.xml

Code here, function captureAndDetect() although I have removed the flags as you suggested

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/TASSCore.py

Also any idea why it will not read the local stream anymore ?

StevenPuttemans commented 7 years ago

Nope ... problem is, you are combining platforms that I am unaware of how it should be used ... maybe you need to find someone with more experience in the matter ...

AdamMiltonBarker commented 7 years ago

I wrote this myself, TechBubble is my company, it does nothing more than wrap opencv it is not the wrapper at fault.

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/TASS.py

Line 99

currentImage,detected = TassCore.captureAndDetect(frame)

fires the function in:

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/Computer-Vision/Python/TASSCore.py

    def captureAndDetect(self,frame):

        faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_FACES"])
        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

        faces = faceCascade.detectMultiScale(gray,
            scaleFactor=self._configs["ClassifierSettings"]["HAAR_SCALE_FACTOR"],
            minNeighbors=self._configs["ClassifierSettings"]["HAAR_MIN_NEIGHBORS"],
            minSize=(30,30)
        )

        if not len(faces):
            faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_FACES2"])
            faces = faceCascade.detectMultiScale(gray,
                scaleFactor=self._configs["ClassifierSettings"]["HAAR_SCALE_FACTOR"],
                minNeighbors=self._configs["ClassifierSettings"]["HAAR_MIN_NEIGHBORS"],
                minSize=(30,30)
            )

        if not len(faces):
            faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_FACES3"])
            faces = faceCascade.detectMultiScale(gray,
                scaleFactor=self._configs["ClassifierSettings"]["HAAR_SCALE_FACTOR"],
                minNeighbors=self._configs["ClassifierSettings"]["HAAR_MIN_NEIGHBORS"],
                minSize=(30,30)
            )

        if not len(faces):
            faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_PROFILES"])
            faces = faceCascade.detectMultiScale(gray,
                scaleFactor=self._configs["ClassifierSettings"]["HAAR_SCALE_FACTOR"],
                minNeighbors=self._configs["ClassifierSettings"]["HAAR_MIN_NEIGHBORS"],
                minSize=(30,30)
            )

        print( "Found " + str(len(faces)) + " face(s)")

        currentImage = os.getcwd()+"/current.jpg"

        if len(faces):

            return frame, faces[0]

        else:

            return frame, None   

Which does nothing but load the haarcascades this is where the error is and it is not related to the wrapper.

Configs mentioned in above snippets:

    "ClassifierSettings":{
        "HAAR_FACES": "Haarcascades/haarcascade_frontalface_default.xml",
        "HAAR_FACES2": "Haarcascades/haarcascade_frontalface_alt.xml",
        "HAAR_FACES3": "Haarcascades/haarcascade_frontalface_alt2.xml",
        "HAAR_PROFILES": "Haarcascades/haarcascade_profileface.xml",
        "HAAR_SMILE": "Haarcascades/haarcascade_smile.xml",
        "HAAR_EYE": "Haarcascades/haarcascade_eye.xml",
        "HAAR_SCALE_FACTOR": 1.3,
        "HAAR_MIN_NEIGHBORS":4,
        "Model":"model/TASSModel.xml",
        "predictionThreshold":3000.0,  
        "height":112,
        "width": 92
    }
AdamMiltonBarker commented 7 years ago

The issue with the mjpeg stream, loading are you suggesting that simply callling:


self.OpenCVCapture = cv2.VideoCapture()
self.OpenCVCapture.open('http://IP:PORT/stream.mjpg'

and then calling


ret, frame = TASS.OpenCVCapture.read()
            if not ret: continue

is the reason it is broken, I think not lol.

StevenPuttemans commented 7 years ago

Is there a reason why you are doing an explicit open? Why not use the direct initializer? Or is that not possible in Python?

As to the config, why go for scaling 1.3? Those are huge steps in the multi scale pyramid!

AdamMiltonBarker commented 7 years ago

Dont quite follow RE the explicit open ? Could you elaborate please?

I noticed you had used 1.1 I will try that but for now that is not an issue. The issue the last week trying to get the mjpeg stream working at the quality that the normal webcam feed has run at for the last year or so, and now the fact that after upgrade (Had to spend the night without sleep reinstalling a new OS and new version of OpenCV as the dependencies from the old version clashed with the new ones), everything is broken lol.

Back to the first issue do you see anything in the mjpeg comment above that suggests that it is not an issue with OpenCV rather than the wrapper, let me know if you do as I am missing it.

RE the error with capture and detect, you mentioned about explicitly opening, maybe the direct initializer will work, no idea have never used that but a bit confused as to why it would break now after working for over a year.

RE the error in capture and detect:

Corrupt JPEG data: 3 extraneous bytes before marker 0xd1
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage

This is happening here:


    def captureAndDetect(self,frame):

        faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_FACES"])
        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

        faces = faceCascade.detectMultiScale(gray,
            scaleFactor=self._configs["ClassifierSettings"]["HAAR_SCALE_FACTOR"],
            minNeighbors=self._configs["ClassifierSettings"]["HAAR_MIN_NEIGHBORS"],
            minSize=(30,30)
        )

Again I am at a total loss as to why, seeing as there have been no problems for over a year (With this part) before upgrade to 3.2.0, and what is the error about corrupt JPEG, I do nothing with jpeg in that function, there is a variable set which I forgot to remove from github related to a jpg but it does absolutely nothing and is not in my code anymore, after adding a print("GOT HERE ") after:

faceCascade = cv2.CascadeClassifier( os.getcwd()+'/'+self._configs["ClassifierSettings"]["HAAR_FACES"])

The code never reaches GOT HERE, as mentioned the path to haarcascade is correct, it is an absolute path, valid and exists.

AdamMiltonBarker commented 7 years ago

OK update

Corrupt JPEG data: 4 extraneous bytes before marker 0xd0

Is coming before you get to the capture and detect function, it is coming from:

print("1")
ret, frame = TASS.OpenCVCapture.read()
if not ret: continue
print("2")

I added the prints in to see where the error was being generated, funnily enough this is the same place the issue with the mjpeg stream is coming from.

OUTPUT:

1
Corrupt JPEG data: 3 extraneous bytes before marker 0xd3
2
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file /home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp, line 4422
/home/ds62hdsa/opencv/opencv-3.2.0/modules/core/src/persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage
StevenPuttemans commented 7 years ago

Dont quite follow RE the explicit open ? Could you elaborate please?

You are doing

  1. an initialization of the videocapture object
  2. the opening of the file using the open() function

While I am doing the opening inside the initialisation by passing the path as an argument to the constructor.

I noticed you had used 1.1 I will try that but for now that is not an issue.

Please, can you stop saying that stuff like this is not an issue ... it could be one of the main reasons why in your previous version the face was missed. If a face thumbles right in between two scales and the scales are seperated to much, then it will not detect anything. I am using 1.05 in most of my applications.

but a bit confused as to why it would break now after working for over a year

Because it is an open source platform and even if people did not intend to, it is perfectly possible that in between versions, someone provided a fix for problem A, without realising it breaks other stuff. Happens about all the time around here.

Corrupt JPEG data: 3 extraneous bytes before marker 0xd1

This is an error generated by libjpeg, not by OpenCV itself. Can you update libjpeg to the latest possible version?

funnily enough this is the same place the issue with the mjpeg stream is coming from

I have been around the OpenCV community for 5 years now and I have not seen a single month without stream issues and MJPEG issues. Life is hard I know it, but I always suggest people to use something else to handle the stream, then load the data into a OpenCV mat using the ->data() accessor. From time to time it works, but it seems heavily dependent on the setup.

AdamMiltonBarker commented 7 years ago

Hi mate just as you replied this I realised you were talking about the stream lol, I was thinking you meant the haars, will check this.

RE 1.1 changed it, it made no difference, I then moved back to the original version of frontal face and not the new one and the issue was no longer there. (EDIT, I found out why, doing wget on the link you provided for the xml actually downloads a HTML page, I missed it was a github page)

RE libjpeg:

sudo apt-get install libjpeg-dev --upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
libjpeg-dev is already the newest version.

The function is now completing and I now get:

Corrupt JPEG data: 4 extraneous bytes before marker 0xd0

Traceback (most recent call last):
  File "TASS.py", line 105, in <module>
    crop = TassCore.resize(TassCore.crop(image, x, y, w, h))
  File "/home/ds62hdsa/IoT-JumpWay-RPI-Examples/Computer-Vision/Python/TASSCore.py", line 87, in crop
    return image[y1:y2, x:x+w]
TypeError: slice indices must be integers or None or have an __index__ method

So this leaves the above error and the fact that the stream no longer works from mjpeg, if you can suggest me a way to get the stream as you said that would be great. Although it is clearly something that needs to be fixed. Still no movement when connecting to mjpeg.

AdamMiltonBarker commented 7 years ago

Slice indices was silly error on my part :D Fixed that and it is now returning detections, incedently, every second like it used to no matter, light, angle etc.

Errors remaining:

Corrupt JPEG data: 2 extraneous bytes before marker 0xd3

IP stream not working.

Getting there ;) Both issues are related to:

ret, frame = TASS.OpenCVCapture.read()
            if not ret: continue

I will try the opening method you mentioned, have used it C++ but not seen an example in Python, will get back to you.

StevenPuttemans commented 7 years ago

(EDIT, I found out why, doing wget on the link you provided for the xml actually downloads a HTML page, I missed it was a github page)

yeah that is indeed an issue, students of mine had the same issues

For the libjpeg

Could you first do a sudo apt-get remove libjpeg* then try to reinstall?

AdamMiltonBarker commented 7 years ago

Ok will do now, I think re the open() it seems to be the way you have to do it in Python. Unless I am mistaken.

AdamMiltonBarker commented 7 years ago

Also when this actually gets sorted I am testing using 640x480, something I noticed comparing your stream video to mine is that for some reason on my side my forehead was all shiny and light was reflecting, not sure why the difference in quality between yours and mine, but with it in 640x480 it does not have that any more, if I can get it working at that resolution it is better than none at all.

AdamMiltonBarker commented 7 years ago

I now get:


Traceback (most recent call last):
  File "TASS.py", line 14, in <module>
    import cv2
ImportError: libgtk-x11-2.0.so.0: cannot open shared object file: No such file or directory

Also Nginx and Motion are broken, will install all now and see if that fixes it.

StevenPuttemans commented 7 years ago

Also when this actually gets sorted I am testing using 640x480, something I noticed comparing your stream video to mine is that for some reason on my side my forehead was all shiny and light was reflecting, not sure why the difference in quality between yours and mine, but with it in 640x480 it does not have that any more, if I can get it working at that resolution it is better than none at all.

Well I grabbed your stream at HD resolution, then resized myself to half in both dimensions before feeding to detector. It could be your data had to much info? Too much detail?

AdamMiltonBarker commented 7 years ago

Yes, possibly I tried resizing and setting FPS with: (EDIT, never mind I see your resize, but Motion is not letting me change the resolution now even if I wanted to lol)

self.OpenCVCapture.set(5, 30) self.OpenCVCapture.set(3,640) self.OpenCVCapture.set(4,480)

Is that not the correct way? I also noticed a massive lag, in my other version it feeds the frames to an A.I on a local server via MQTT which then runs the frames through a model to identify them, I was noticing that the images were coming in maybe ten minutes behind, I tried looping for 30 frames and then sending one frame to the A.I but it did not make a difference.

AdamMiltonBarker commented 7 years ago

Issue with libjpeg fixed for OpenCV:

sudo apt-get remove libjpeg*
sudo apt-get install \
  libjpeg-dev \
  libtiff5-dev \
  libjasper-dev \
  libpng12-dev \
  libavcodec-dev \
  libavformat-dev \
  libswscale-dev \
  libeigen3-dev \
  libxvidcore-dev \
  libx264-dev \
  libgtk2.0-dev

However Motion and Nginx both broken.

Never mind fixed that.

AdamMiltonBarker commented 7 years ago

Ok all errors gone, only one thing remains:

Using the mjpeg stream, it never gets past this:

ret, frame = TASS.OpenCVCapture.read()
            if not ret: continue
AdamMiltonBarker commented 7 years ago

Changing this:


self.OpenCVCapture = cv2.VideoCapture()
self.OpenCVCapture.open('http://IP:PORT/stream.mjpg')

to this:

self.OpenCVCapture = cv2.VideoCapture('http://IP:PORT/stream.mjpg')

has not caused any errors but still I cannot access the feed:

 sudo python3 TASS.py
Subscribed to Device Commands Channel
LOADING VIDEO CAMERA
Published to Device Status
rc: 0
Published: 2
Subscribed: TASS
LOADED STREAM & MODEL

... and that is where it stays, sat there doing nothing lol.

AdamMiltonBarker commented 7 years ago

@StevenPuttemans hi mate any update on the issue with the IP stream in the new version mate?

StevenPuttemans commented 7 years ago

I am using the latest version and was perfectly able to capture your stream, so I am unsure what you are expecting from me now?

AdamMiltonBarker commented 7 years ago

Possibly should explain it again to verify the last remaining issue we have got down to, in Python:

self.OpenCVCapture = cv2.VideoCapture('http://IP:PORT/stream.mjpg')

Also tried:

self.OpenCVCapture = cv2.VideoCapture()
self.OpenCVCapture.open('http://IP:PORT/stream.mjpg')

In class named Tass.

ret, frame = TASS.OpenCVCapture.read()
            if not ret: continue

The script will never get passed this line. ret is always empty.

alalek commented 7 years ago

Add dump of this: print(cv2.getBuildInformation())

AdamMiltonBarker commented 7 years ago

OK cheers will do two mins.

AdamMiltonBarker commented 7 years ago

For a little extra insight, this is the document I wrote which explains the full process I took to install the new version:

https://github.com/TechBubbleTechnologies/IoT-JumpWay-RPI-Examples/blob/master/_DOCS/2-Installing-OpenCV-3-2-0.md

Output of print(cv2.getBuildInformation())

General configuration for OpenCV 3.2.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/ds62hdsa/opencv/opencv_contrib-3.2.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2017-02-13T03:26:05Z
    Host:                        Linux 4.4.38-v7+ armv7l
    CMake:                       3.6.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               RELEASE

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 4.9.2)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -mfpu=neon-fp16 -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -mfpu=neon-fp16 -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -mfpu=neon-fp16 -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -mfp16-format=ieee -mfpu=neon -ffunction-sections -fvisibility=hidden -mfpu=neon-fp16 -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):
    Linker flags (Debug):
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          /usr/lib/arm-linux-gnueabihf/libpng.so /usr/lib/arm-linux-gnueabihf/libz.so /usr/lib/arm-linux-gnueabihf/libtiff.so /usr/lib/arm-linux-gnueabihf/libjasper.so /usr/lib/arm-linux-gnueabihf/libjpeg.so gtk-x11-2.0 gdk-x11-2.0 pangocairo-1.0 atk-1.0 cairo gdk_pixbuf-2.0 gio-2.0 pangoft2-1.0 pango-1.0 gobject-2.0 glib-2.0 fontconfig freetype gthread-2.0 avcodec avformat avutil swscale avresample dl m pthread rt
    3rdparty dependencies:       libwebp IlmImf libprotobuf tegra_hal

  OpenCV modules:
    To be built:                 core flann imgproc ml photo reg surface_matching video dnn freetype fuzzy imgcodecs shape videoio highgui objdetect plot superres xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo tracking videostab xfeatures2d ximgproc aruco optflow phase_unwrapping stitching structured_light python3
    Disabled:                    world contrib_world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 ts viz cnn_3dobj cvv hdf matlab sfm

  GUI:
    QT:                          NO
    GTK+ 2.x:                    YES (ver 2.24.25)
    GThread :                    YES (ver 2.42.1)
    GtkGlExt:                    NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        /usr/lib/arm-linux-gnueabihf/libz.so (ver 1.2.8)
    JPEG:                        /usr/lib/arm-linux-gnueabihf/libjpeg.so (ver )
    WEBP:                        build (ver 0.3.1)
    PNG:                         /usr/lib/arm-linux-gnueabihf/libpng.so (ver 1.2.50)
    TIFF:                        /usr/lib/arm-linux-gnueabihf/libtiff.so (ver 42 - 4.0.3)
    JPEG 2000:                   /usr/lib/arm-linux-gnueabihf/libjasper.so (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO
    GDCM:                        NO

  Video I/O:
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES
      avcodec:                   YES (ver 56.1.0)
      avformat:                  YES (ver 56.1.0)
      avutil:                    YES (ver 54.3.0)
      swscale:                   YES (ver 3.0.0)
      avresample:                YES (ver 2.1.0)
    GStreamer:                   NO
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    OpenNI2:                     NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    Aravis SDK:                  NO
    UniCap:                      NO
    UniCap ucil:                 NO
    V4L/V4L2:                    NO/YES
    XIMEA:                       NO
    Xine:                        NO
    gPhoto2:                     NO

  Parallel framework:            pthreads

  Other third-party libraries:
    Use IPP:                     NO
    Use VA:                      NO
    Use Intel VA-API/OpenCL:     NO
    Use Lapack:                  NO
    Use Eigen:                   YES (ver 3.2.2)
    Use Cuda:                    NO
    Use OpenCL:                  YES
    Use OpenVX:                  NO
    Use custom HAL:              YES (carotene (ver 0.0.1))

  OpenCL:                        <Dynamic loading of OpenCL library>
    Include path:                /home/ds62hdsa/opencv/opencv-3.2.0/3rdparty/include/opencl/1.2
    Use AMDFFT:                  NO
    Use AMDBLAS:                 NO

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.9)

  Python 3:
    Interpreter:                 /usr/bin/python3.4 (ver 3.4.2)
    Libraries:                   /usr/lib/arm-linux-gnueabihf/libpython3.4m.so (ver 3.4.2)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)
    packages path:               lib/python3.4/dist-packages

  Python (for build):            /usr/bin/python2.7

  Java:
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        Matlab not found or implicitly disabled

  Tests and samples:
    Tests:                       NO
    Performance tests:           NO
    C/C++ Examples:              NO

  Install path:                  /usr/local

  cvconfig.h is in:              /home/ds62hdsa/opencv/opencv-3.2.0/build
-----------------------------------------------------------------
StevenPuttemans commented 7 years ago

Btw, just did

spu@TOBCAT:~$ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cap = cv2.VideoCapture('xxxx/stream.mjpg')

And after some configuration and connecting, I am perfectly able to continue programming ... so that would mean it worked to initialize the stream right?

AdamMiltonBarker commented 7 years ago

Why have you just posted the live url mate, I specifically asked not to, I have posted the code not working above.

I can connect that is not the issue, the issue it is always empty as explained.

@StevenPuttemans can you remove that url please.

AdamMiltonBarker commented 7 years ago

https://github.com/opencv/opencv/issues/8188#issuecomment-279423073

https://github.com/opencv/opencv/issues/8188#issuecomment-279703195