Posting on behalf of Dave Akerman who asked the question on Twitter:
Quick question - is there a simple way to find the model or resolution of Pi camera connected, from a bash script? No doubt it can be done in Python with picamera but is there something simpler ?
Thanks
- JonnyAlpha
- Raspberry Pi Certified Educator
- Posts: 580
- Joined: Sat Nov 02, 2013 2:06 pm
PiCamera Version
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera
- DougieLawson
- Posts: 40821
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: PiCamera Version
Take a photo, read the EXIF data.
Which spits out this stuff
Code: Select all
from PIL import Image
from PIL.ExifTags import TAGS
img = Image.open('/tmp/somesuch.jpg')
exif_data = img._getexif()
for tag, value in exif_data.items():
print TAGS.get(tag, tag), value
Which spits out this stuff
Code: Select all
ImageWidth 2592
ImageLength 1944
ApertureValue (30705, 10000)
DateTimeOriginal 2018:01:01 20:24:20
DateTimeDigitized 2018:01:01 20:24:20
MaxApertureValue (30705, 10000)
ExifVersion 0220
ComponentsConfiguration
Flash 0
FocalLength (35976, 10000)
ExifImageWidth 2592
Make RaspberryPi
Model RP_ov5647
YCbCrPositioning 1
XResolution (72, 1)
YResolution (72, 1)
ExposureTime (124990, 1000000)
ExifInteroperabilityOffset 908
ExposureProgram 3
ColorSpace 1
ISOSpeedRatings 640
ResolutionUnit 2
WhiteBalance 0
MeteringMode 2
FNumber (28984, 10000)
DateTime 2018:01:01 20:24:20
ShutterSpeedValue (3000115, 1000000)
FlashPixVersion 0100
ExifImageHeight 1944
ExposureMode 0
ExifOffset 192
BrightnessValue (111, 100)
MakerNote ev=-1 mlux=-1 exp=124990 ag=1536 focus=255 gain_r=1.164 gain_b=1.769 greenness=9 ccm=7914,-3202,-610,-1226,5800,-474,628,-3484,6962,0,0,0 md=0 tg=612 612 oth=0 0 b=0 f=612 612 fi=0 ISP Build Date: Dec 1 2017, 16:29:01 VC_BUILD_ID_VERSION: 38ac72569d7fbd7cf75754d9f14c2495416aaee7 (clean) VC_BUILD_ID_USER: dc4 VC_BUILD_ID_BRANCH: master
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
-
- Raspberry Pi Engineer & Forum Moderator
- Posts: 10566
- Joined: Wed Dec 04, 2013 11:27 am
- Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.
Re: PiCamera Version
No bash command, but the function set_sensor_defaults in RaspiStill retrieves the data via the camera_info component.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
I'm not interested in doing contracts for bespoke functionality - please don't ask.
- JonnyAlpha
- Raspberry Pi Certified Educator
- Posts: 580
- Joined: Sat Nov 02, 2013 2:06 pm
Re: PiCamera Version
Many thanks all. I will pass it on.
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera
Re: PiCamera Version
Cheers guys. Dougie's solution is close in concept to what I've done, which is to take a photo with raspistill then check the pixel size in the file:
This is for a camera script on some balloon trackers. I'm flying 3 of those trackers soon on the same payload, and haven't decided yet which cameras to use where - I have a selection of V2 and V1 cameras, including a couple of "fisheye" versions with the Omnivision sensor. I want to be able to swap cameras around once I've built the payload (so I can get the best views from each position) and I don't want to then have to mess around with the scripts to change image resolutions to best suit the sensors.
Code: Select all
raspistill -o test.jpg
jpeg=$(file test.jpg)
rm -f test.jpg
if [[ $jpeg == *"2592"* ]]; then
echo "Old camera"
else
echo "New camera"
fi
- DougieLawson
- Posts: 40821
- Joined: Sun Jun 16, 2013 11:19 pm
- Location: A small cave in deepest darkest Basingstoke, UK
- Contact: Website Twitter
Re: PiCamera Version
I never knew the file command read some of the EXIF data, neat trick.
Any language using left-hand whitespace for syntax is ridiculous
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.
Any requirement to use a crystal ball or mind reading will result in me ignoring your question.
Re: PiCamera Version
I didn't either! I expected to need to install something, but found a web post somewhere that mentioned that file does it.