nischi / MMM-Face-Reco-DNN

Face recognition with opencv and deep neural network
MIT License
91 stars 46 forks source link

Make image brighter #23

Closed AnduriI closed 1 year ago

AnduriI commented 4 years ago

Hey,

I tried your module because I never got the old one working. I have one big problem and am not able to correct for this: I have my picam mounted behind the mirror glass. With raspistill I can take reasonable good pictures, but with the opencv3 module I could only get very dark pictures. As far as I could find out the method of acquiring pictures is different. Is there a way to boost brightness or contrast for the stream?

Best Regards, Anduril

nischi commented 4 years ago

Hi @AnduriI

Thanks for give my module a chance. At the moment you can't configure this. But i will check if I can add an option for that. Thanks for the hint.

Regards, Thierry

AnduriI commented 4 years ago

Hi @nischi

thanks for the fast reply. I'm not realy into python programming, otherwise I would try to help coding. But I'm very interested in CV and as I said already tried some things with OpenCV3. I had a look at the imutils package and found a function called 'adjust_brightness_contrast' - maybe that can be optionally inserted after the stream capture. I will try to play arround with it and report back in case I find something usefull.

Regards, Anduril

nischi commented 4 years ago

Hi @AnduriI

That would be awesome, I will check it as well if I find some time.

Regards, Thierry

AnduriI commented 4 years ago

Hey @nischi,

I wrote a little test-script in python to test multiple things to get better pictures. First I tried your way of capturing at the moment and then I tried a different approach following this link. The image quality of the later one seems a little better, is there a reason you prefer the current one? I also tried the 'adjust_brightness_contrast function and it works perfect. I'm still testing the optimal parameters for my usecase, but I still want to share my code with you.

It is still only my test-code, so only proof of concept code. Hope you can use at least a little of it.

# USAGE
# python pi_face_recognition.py --cascade haarcascade_frontalface_default.xml --encodings encodings.pickle

# import the necessary packages
from imutils.video import FPS, VideoStream
from datetime import datetime
from imutils import adjust_brightness_contrast
from picamera.array import PiRGBArray
from picamera import PiCamera
import face_recognition
import argparse
import imutils
import pickle
import time
import cv2
import json
import sys
import signal
import os

vs = VideoStream(usePiCamera=True).start()

time.sleep(1.0)

originalFrame = vs.read()
frame = imutils.resize(originalFrame, width=500)

cv2.imwrite('Test1.png',frame)

vs.stop()

time.sleep(1.0)

camera = PiCamera()
rawCapture = PiRGBArray(camera)

time.sleep(1.0)

camera.capture(rawCapture, format="bgr")
originalFrame = rawCapture.array
frame = imutils.resize(originalFrame, width=500)

cv2.imwrite('Test3.png',frame)

adjusted = adjust_brightness_contrast(frame, contrast=50, brightness=100)
cv2.imwrite('Test4.png',adjusted)
sergge1 commented 4 years ago

hi there, @nischi @AnduriI

the same for me - video stream from the picam (original) looks too dark. Further, putting camera behind the glass makes very very poor (dark) quality of the video stream, so reco precision drops down dramatically. I am in for increasing of brughtness/contrast for the video stram

nischi commented 4 years ago

@AnduriI Thanks a lot for the script, i will test a little bit with this as well. I would prefer that the raspbi adjust the image automaticaly. So it would also work if the room is a little darker in the evening. I will give a try. My camera is hidden in the wood and not behind the mirror :)

@sergge1

I will try it in the near future. At the moment i have a little less time.

ChrizZz90 commented 4 years ago

guys, that is a very interesting improvement. Maybe you can find a way to increase the image resolution. Right now it is 640x480 and I am using a wide focus webcam but the pictures are too small (or the people in front of the cam).

Maybe I asked that topic somewhere before, I don't not :)

SILLEN69 commented 1 year ago

hey has anyone found a way to do this? when i put the camera behind the mirror its completley black if i shine the flashlight at it i can barley see a light can i somhow just up the brightness. i dont understand how to use @AnduriI test script.

SILLEN69 commented 1 year ago

Because the way my mirror is set up i have no place too put it outside i need to have it inside. I could just tape the camera to the wall outside and that's my temporary solution but it looks super ugly

nischi commented 1 year ago

hi @SILLEN69 i added now two new configs.

      // Brightness, negative is darker, positive is brighter
      brightness: 0,
      // Contrast, positive value for more contrast
      contrast: 0,

It worked on my setup. For example brightness to 50 make it a "little" brighter.

SILLEN69 commented 1 year ago

Wow thank you so much i will try this right now

nischi commented 1 year ago

Does it work?

SILLEN69 commented 1 year ago

Yes it works great i haven't tried the contrast yet because I don't know what setting is good i will have to try my way too good aetting. Thank you so much