guardianproject / haven

Haven is for people who need a way to protect their personal spaces and possessions without compromising their own privacy, through an Android app and on-device sensors
https://guardianproject.github.io/haven/
GNU General Public License v3.0
6.58k stars 728 forks source link

Camera motion detection not working in 0.2.0-beta3 #383

Open mig5 opened 5 years ago

mig5 commented 5 years ago

In 0.2.0-beta3, camera motion detection simply doesn't work.

Under 'Camera Sensitivity' in the settings, it stays at '0% motion' detected, no matter how much I move the phone around and capture movement. The cameras themselves work in the app, but no motion is registered in Haven anymore.

Sound and movement (moving the phone itself) detection works, but no camera motion.

Device is a Samsung Galaxy J1 mini, model SM-J105Y.

It used to work on this device, but I can't remember what version I was on before upgrading. I can't downgrade to an older version (I get an error in F-Droid).

mig5 commented 5 years ago

Uninstalling and installing 0.2.0-beta1 from F-Droid, I only get a black screen for Camera Sensitivity.

Rolling back to 0.1.0-RC-1 seems to restore camera motion detection for me :/

archie94 commented 5 years ago

In 0.2.0-beta3, camera motion detection simply doesn't work.

Under 'Camera Sensitivity' in the settings, it stays at '0% motion' detected, no matter how much I move the phone around and capture movement. The cameras themselves work in the app, but no motion is registered in Haven anymore.

This is reproducible for me. In earlier versions setting the Camera sensitivity to 0 used to trigger Logs at the slightest motion. Not so in the recent build.

lukeswitz commented 5 years ago

@archie94, can you check this commit and see if it solves/helps the issue? 19890a22b9f0f094fb1b392cda185ec2673606a4
Was seeing only 0% on legacy devices until this point, let me know. Thank you

archie94 commented 5 years ago

@lukeswitz Much better đź‘Ť

For some reason the text which shows the % of motion detected is not responsive on master branch. Much better when on 19890a2

CameraCornet commented 5 years ago

I'm on latest github,compiling from source. This Calibration / Settings screen just isn't working very well.

To me there is a fundamental design issue here: I suggest a single frame output (bottom status) isn't really sufficient. A history graph of the past 3 seconds (real time) would seem far more useful in calibrating detection.

As a quick debugging hack to reflect each time the status changes: Adding a variable changeIndex of how often the output has been touched.

   // add class variable to track screen updates
   private int changeIndex = 0;
   private String detectSaveOutput = "";

`

BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {

        changeIndex++;
        int eventType = intent.getIntExtra("type",-1);
        boolean detected = intent.getBooleanExtra("detected",true);
        int percChanged = intent.getIntExtra("changed",-1);

        if (percChanged != -1)
        {
            // "C" stands for "current"
            mTxtStatus.setText(percChanged + "% motion detected C" + changeIndex + detectSaveOutput);
            if (percChanged > 0) {
                // "P" stands for "previous detection"
                detectSaveOutput = " P" + changeIndex + ":" + percChanged + "%";
            }
        }
    }
};`
CameraCornet commented 5 years ago

My baseline is build 118

commit a52455e9d594484aeea5b69b68334950c164f962 (tag: 0.2.0-alpha-5, origin/master, 
origin/HEAD, master)
Author: n8fr8 <nathan@freitas.net>
Date:   Wed Oct 3 16:43:53 2018 -0400

    update to version 118

This older camera motion code did annotations of the changes in the frames. But more notable, the frame rate of comparing frames was much higher. Like 4 to 8 FPS. With the latest source checkout, sometimes 1 to 3 seconds can pass with no frames being analyzed for detection.

I think FPS of the comparison needs to be exposed - as it's going to impact battery consumption and also how quickly someone could 'dash' in front of a camera and not be detected if the rate of comparison between frames is too low.

indiglofae commented 5 years ago

Have you checked the camera settings to see if it works better with HD off?

On Thu, Apr 4, 2019, 7:50 PM CameraCornet notifications@github.com wrote:

My baseline is build 118

commit a52455e9d594484aeea5b69b68334950c164f962 (tag: 0.2.0-alpha-5, origin/master, origin/HEAD, master) Author: n8fr8 nathan@freitas.net Date: Wed Oct 3 16:43:53 2018 -0400

update to version 118

This older camera motion code did annotations of the changes in the frames. But more notable, the frame rate of comparing frames was much higher. Like 4 to 8 FPS. With the latest source checkout, sometimes 1 to 3 seconds can pass with no frames being analyzed for detection.

I think FPS of the comparison needs to be exposed - as it's going to impact battery consumption and also how quickly someone could 'dash' in front of a camera and not be detected if the rate of comparison between frames is too low.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/guardianproject/haven/issues/383#issuecomment-480112707, or mute the thread https://github.com/notifications/unsubscribe-auth/AhZXIU5XPEYWramQ8ZUaXiCPMNbUef_Bks5vdp3cgaJpZM4bWHWj .

CameraCornet commented 5 years ago

@indiglofae Haven camera settings? I don't see such a setting. And to add, I don't have video on.

This is looking at my Nokia 6.1 device, running Android ``9.

indiglofae commented 5 years ago

Haven uses your Android camera. Try turning it off in your Android settings and see if it works. I know it sounds too simple, but it just might work.

On Thu, Apr 4, 2019, 8:33 PM CameraCornet notifications@github.com wrote:

@ndiglofae Haven camera settings? I don't see such a setting. And to add, I don't have video on.

This is looking at my Nokia 6.1 device, running Android 9.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/guardianproject/haven/issues/383#issuecomment-480119354, or mute the thread https://github.com/notifications/unsubscribe-auth/AhZXIQuMUfzwZaA0yAgyag4x2iZI_1c8ks5vdqfkgaJpZM4bWHWj .

andrewtchin commented 5 years ago

This is also present on a Moto E4 running Android 7.1.1 with Haven 0.2.0-beta-5

CameraCornet commented 4 years ago

I installed Haven from Github on a Chromebook, Chrome OS 74.0.3729.159 Official Build, and the same thing is happening. The slider for sensitivity seems to make little difference. It sometimes detects motions if I do very dramatic things, but otherwise it is very broken.

CameraCornet commented 4 years ago

Playing around...

The code checks each Frame getData() and getSize() against null twice. Perhaps threading is causing these problems?

getData() and getSize() is checked for null before submitting to ThreadPool:

https://github.com/guardianproject/haven/blob/b4b55a1f7c94a491388620c477d18e66cc198b44/src/main/java/org/havenapp/main/ui/CameraViewHolder.java#L244

and then on the thread, null is checked a second time inside the method processNewFrame:

https://github.com/guardianproject/haven/blob/b4b55a1f7c94a491388620c477d18e66cc198b44/src/main/java/org/havenapp/main/ui/CameraViewHolder.java#L345

NOTE: DataSpotA is class of static int variables to do counting at runtime of each execution branch.

` // revised process

        public void process(@NonNull Frame frame) {

            long now = System.currentTimeMillis();
            if (now < CameraViewHolder.this.lastTimestamp + DETECTION_INTERVAL_MS) {
                DataSpotA.processFrameTimeSkipCount++;
                return;
            }

            final byte[] frameData = frame.getData();
            final Size frameSize = frame.getSize();
            if (frameData == null) {
                DataSpotA.processFrameDataNullCount++;
                return;
            } else if (frameSize == null) {
                DataSpotA.processFrameSizeNullCount++;
                return;
            }

            CameraViewHolder.this.lastTimestamp = now;

            // OLD: if (frame.getData() != null && frame.getSize() != null) {

                if (!doingVideoProcessing) {
                    // OLD: mDecodeThreadPool.execute(() -> processNewFrame(frame));
                    mDecodeThreadPool.execute(() -> processNewFrameData(frameData, frameSize));
                } else {
                    mEncodeVideoThreadPool.execute(() -> recordNewFrame(frame));
                }
            //}
        }

`

This seems to work much better, as the frame object is not passed to the ThreadPool but instead the byte[] array and size object itself.

Otherwise, the original code, is hitting a lot of nulls on the getData() and getSize() by the time it makes it into the ThreadPool.

Following along here on what is happening?

lukeswitz commented 4 years ago

Video recording was a good intention feature that happened to break the app entirely for a lot of folks.

Threading totally a problem, and hard to say without having written the camera activity if what you’re pointing out is the cause, but video breaks all motion capture for devices < lollipop (5.1). I’ll try the code and report back

Hoping to see some activity resume here shortly. Cheers

CameraCornet commented 4 years ago

Another observation...

The first thing the method does is check DETECTION_INTERVAL_MS - but is that really what you want if you are capturing video?

If you are in the middle of an security incident, I would suggest that every single frame be processed.

CameraCornet commented 4 years ago

Code is public: https://github.com/CameraCornet/haven/tree/CameraRework0

CameraCornet commented 4 years ago

I hacked in a switch/case to allow the older MotionDetector code with visual annotation to work with the latest github source.

Video recording may be broken, I haven't tested this much. Study the commit and you will see a variable and switch/case used as to old vs. new code.

https://github.com/CameraCornet/haven/commits/SwitchMotionDetection0

lukeswitz commented 4 years ago

Strong work- Thanks @CameraCornet, looking forward to reviewing later. I like the idea of actually capturing the incident instead of the first frame of motion. Exactly what we need here. Cheers and thanks again for the efforts!

n8fr8 commented 4 years ago

Yes, this is the approach I have been hoping for. Coming up for air from other projects, and looking forward to digging back into Haven.

CameraCornet commented 4 years ago

With the current (latest) code, i've integrated 2 old motion routines. Notably the commit a52455e9d594484aeea5b69b68334950c164f962 branch - which I had worked with for months and is my baseline of experience with camera motion detection.

I am a bit lost, as I seem to be running the code from commit a52455e9d594484aeea5b69b68334950c164f962 integrated with the latest, but it isn't behaving the same. Still trying to figure out why.

To me, this raises some issues regarding data testing. I think a natural progression is to allow masking of parts of the frame as many IP Camera systems allow. To test this, a static set of motion-data might make sense? I'm looking over: http://lear.inrialpes.fr/research/motionboundaries/

rockofclay commented 4 years ago

Can't seem to get this working on 0.2.0-beta-5. Using an EKO Star LTE g60 running Android 7.0. Camera preview displays in camera sensitivity setting, but "XX% motion detected" rarely updates (once every 5 minutes or so).