Reputation: 57
I am trying to take a picture using the webcam on my Mac. I am using OpenCV to do so. However, if the lights are off in the room, the picture is extremely dark. Is there any way to use 'flash' to get light into the image? Or are there any other alternatives to get light into the image?
If you have any questions or need more information, feel free to ask.
Here is my code to take a picture:
import cv2
camera = cv2.VideoCapture(0)
input('Press Enter to capture')
return_value, image = camera.read()
cv2.imwrite('opencv'+'.png', image)
del(camera)
Upvotes: 2
Views: 2139
Reputation: 4049
You can display a white image on the screen to make a "flash":
import cv2
import numpy as np
flash_lite = np.ones((1080,1920), np.uint8) * 255
camera = cv2.VideoCapture(0)
input('Press Enter to capture')
cv2.namedWindow ('flash', cv2.WINDOW_NORMAL)
cv2.setWindowProperty ('flash', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow ('flash', flash_lite)
cv2.waitKey(100)
return_value, image = camera.read()
cv2.destroyWindow('flash')
cv2.imwrite('opencv.png', image)
Upvotes: 1
Reputation: 684
Since you always turning on your screen. You can increase the camera bightness
cam.set(cv2.CAP_PROP_BRIGHTNESS, brightness)
You can get the current brightness from the camera using this
brightness = cam.set(cv2.CAP_PROP_BRIGHTNESS.get(10)
Then try play with the brightness
Please take note that this will affect your image processing.Its better get a USB light source for this.
For more control you can refer to this
I dont have MAc maybe you can consider this if works create script call from your python
Upvotes: 0