pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
983 stars 172 forks source link

How to mask part of the picture #100

Closed amcaw closed 3 years ago

amcaw commented 3 years ago

Thanks for this project, great stuff, works like a charm ! It is more a question than an issue : is there a way to mask part of the picture so I only capture the motion tracking area (i.e. only the part inside of the "red box") ?

So, first picture : what I get. Second picture : what I want.

Should I add something in config.py in Pi Camera Settings ? Or add some kind of zoom in the image to only display what's in the red box ?

Thanks !

v1 copy v2 copy

pageauc commented 3 years ago

Yes you can override the automatic speed motion window in config.py using the settings below. Note uncomment x_left, x_right and y_upper. variables. y_lower is already uncommented. Set these variables to the location that you want. 0,0 is the top left corner of the full size image. Make sure to keep settings within the full image dimensions You can also move camera position as well.. This should do what you want. Let me know if this answers you question.

See config.py settings and comments below

# Note: To see motion tracking crop area on images, Set variable image_show_motion_area = True

# Allow user to customize the motion crop area (width) x values
# If variable not found then values will be set automatically based on image size.
# x_left = 50          # uncomment and change values to override auto calculate
# x_right = 300        # uncomment and change values to override auto calculate

# Allow user to customize the motion crop area (height) y values
# If variables not found then values will be set automatically base on image size.
# y_upper = 60         # uncomment and change values to override auto calculate
y_lower = 150          # uncomment and change values to override auto calculate
amcaw commented 3 years ago

Thanks a lot for your reply ! Your explanations and code seem to be related to the size of the crop area (the "red box" then). My question was about cropping the whole picture to keep only what's inside the red box (to hide houses in front of the camera and only "see" the road and the cars passing by). A bit like in the pics below.

I saw this in your code, but couldn't find how to make it work. But maybe it's not related to what I'm trying to do...

# crop image to motion tracking area only try: image_crop = image[y_upper:y_lower, x_left:x_right] image_ok = True

Thanks anyway, your tool is awesome.

s1 s2

pageauc commented 3 years ago

The crop area can be saved as an image although it would be smaller. Note: Only motion inside the box is tracked. You can add a save of the cropped image instead of the full image

eg at approx line 1301 change image2 to image_crop

                            # Resize and process previous image
                            # before saving to disk
                            *prev_image = image2*

change to

prev_image = image_crop

You can give that a try. make sure config.py variable image_text_on = False since image size will be smaller.

Let me know if this works

On Thu, Sep 30, 2021 at 1:52 PM amcaw @.***> wrote:

Thanks a lot for your reply ! Your explanations and code seem to be related to the size of the crop area (the "red box" then). My question was about cropping the whole picture to keep only what's inside the red box (to hide houses in front of the camera and only "see" the road and the cars passing by). A bit like in the pics below.

I saw this in your code, but couldn't find how to make it work. But maybe it's not related to what I'm trying to do...

crop image to motion tracking area only try: image_crop =

image[y_upper:y_lower, x_left:x_right] image_ok = True

Thanks anyway, your tool is awesome.

[image: s1] https://user-images.githubusercontent.com/42608053/135505574-67e09e70-2938-44e2-833b-39bf50942a73.jpg [image: s2] https://user-images.githubusercontent.com/42608053/135505559-d84d7b9e-465e-4543-a969-ca0339a30a9f.jpg

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/100#issuecomment-931537605, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZGDFQF4YOPZDQIPZYDUESPVBANCNFSM5FCB644Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

amcaw commented 3 years ago

Thanks, it's working with the explanations you provided !