Reputation: 3048
Are there any ways to set the camera in raspberry pi to take black and white image?, like using some commands / code in picamera library?
Since I need to compare the relative light intensity of a few different images, I'm worried that the camera will already so some adjustments itself when the object is under different illuminations, so even if I convert the image to black and white later on the object's 'true' black and white image will have been lost.
thanks
edit: basically what I need to do is to capture a few images of an object when the camera position is fixed, but the position of the light source is changed (and so the direction of illumination is changed as well). Then for each point on the image I will need to compare the relative light intensity of the different images. As long as the light intensity, or the 'brightness' of all the images are relative to the same scale, then it's ok, but I'm not sure if this is the case. I'm sure if the camera will adjust something like contrast automatically itself when an image is 'inherently' darker or brighter.
Upvotes: 2
Views: 21371
Reputation: 104
To get a black and white image (monochrome, grayscale), just configure your camera. Create a "takeashot.py" ( sudo nano takeashot.py ):
import picamera # import files
camera = picamera.PiCamera() # initialize camera
camera.color_effects = (128,128) # turn camera to black and white
camera.capture('image1.jpg') # take a shot
Execute: sudo python takeashot.py
That´s it
You can learn more at 10. API - picamera.camera Module
Under color_effects, you read "to make the image black and white set the value to (128, 128)."
Upvotes: 5
Reputation: 70967
v4l2-ctl -c color_effects=1
From:
v4l2-ctl -L
User Controls ... color_effects (menu) : min=0 max=15 default=0 value=1 0: None 1: Black & White 2: Sepia ...
Nota: I've done this successfully, while my camera was running!
Upvotes: 2
Reputation: 9888
What do you mean by "black and white image," in this case? There is no "true" black and white image of anything. You have sensors that have some frequency response to light, and those give you the values in the image.
In the case of the Raspberry Pi camera, and almost all standard cameras, there are red, green and blue sensors that have some response centered around their respective frequencies. Those sensors are laid out in a certain pattern, as well. If it's particularly important to you, there are cameras that only have an array of a single sensor type that is sensitive to a wider range of frequencies, but those are likely going to be considerable more expensive.
You can get raw image data from the raspi camera with picamera. This is not the "raw" format described in the documentation and controlled by format
, which is really just the processed data before encoding. The bayer
option will return the actual raw data. However, that means you'll have to deal with processing by yourself. Each pixel in that data will be from a different color sensor, for example, and will need to be adjusted based on the sensor response.
The easiest thing to do is to just use the camera normally, as you're not going to get great accuracy measuring light intensity in this way. In order to get accurate results, you'd need calibration, and you'd need to be specific about what the data is for, how everything is going to be illuminated, and what data you're actually interested in.
Upvotes: 3