How to make OpenCV immune to changes in light?

asked 2018-05-26 04:09:03 -0600

updated 2018-05-26 04:14:45 -0600

berak gravatar image

I keep working on monitoring code and I can't find a good way to compare images. Best I've got so far is nrmse but nrmse doesn't do well when sun hides behind clouds. What is the best approach to compare images when camera sits still in one place?

counter = 0

camera_name = "Pi"
camera_fps = 30

# Create a VideoCapture object
camera_feed = cv2.VideoCapture(0)

# Check if camera opened successfully
if (camera_feed.isOpened() == False):
    print("Unable to read camera feed")

# Default resolutions of the frame are obtained.The default resolutions are system dependent.
frame_width = int(camera_feed.get(3))
frame_height = int(camera_feed.get(4))

out = cv2.VideoWriter('outpy.flv', cv2.VideoWriter_fourcc('F', 'L', 'V', '1'), camera_fps, (frame_width, frame_height))

while (True):
    ret, frame = camera_feed.read()

    if ret == True:
        counter += 1
        if not counter % camera_fps:
            for image in source_images:
                print(counter)
                nrmse_of_frame = nrmse(get_image_from(frame), source_images[image])
                if nrmse_of_frame < 0.95:
                    print("NRMSE of %s:" % image, nrmse_of_frame)

        # Display the resulting frame    
        cv2.imshow('frame', frame)

        # Press Q on keyboard to stop recording
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Break the loop
    else:
        break

camera_feed.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

Comments

you'll probably have to explain, where nrmse comes from, and what it does !

also, to compare images -- this is far too broad. what are you trying to achieve ? what is the problem, you're trying to solve ?

berak gravatar imageberak ( 2018-05-26 04:13:01 -0600 )edit

NRMSE is short for Normalized root-mean-square error. What I want to do is to compare images every second and if they don't much then start recording video. As you can see current frame is compared with image from source images that are made at the start of monitoring session (both are in grayscale)

JKarrie gravatar imageJKarrie ( 2018-05-26 04:20:47 -0600 )edit

As you can see current frame is compared with image from source images that are made at the start of monitoring session (both are in grayscale)

look at the code you show, again, we canot see any of it !

have a look at equalizeHist(), CLAHE, bioinspired::retina to overcome problems with lighting changes

(but you probably want to record the original bgr images from your webcam)

berak gravatar imageberak ( 2018-05-26 04:34:09 -0600 )edit