User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 569
Joined: Sat Nov 02, 2013 2:06 pm

PiCamera Version

Tue Jan 23, 2018 7:00 pm

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
Raspberry Pi Certified Educator. Main Hardware - Raspberry Pi 1 model B revision 2, Raspberry Pi 2 model B, Pi Camera

User avatar
DougieLawson
Posts: 35797
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: PiCamera Version

Wed Jan 24, 2018 9:17 pm

Take a photo, read the EXIF data.

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
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7137
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: PiCamera Version

Thu Jan 25, 2018 10:15 am

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.

User avatar
JonnyAlpha
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 569
Joined: Sat Nov 02, 2013 2:06 pm

Re: PiCamera Version

Fri Jan 26, 2018 10:38 pm

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

User avatar
daveake
Posts: 182
Joined: Thu Jul 12, 2012 12:07 am

Re: PiCamera Version

Fri Jan 26, 2018 11:13 pm

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:

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
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.

User avatar
DougieLawson
Posts: 35797
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: PiCamera Version

Sat Jan 27, 2018 9:45 am

I never knew the file command read some of the EXIF data, neat trick.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
daveake
Posts: 182
Joined: Thu Jul 12, 2012 12:07 am

Re: PiCamera Version

Wed Jan 31, 2018 2:02 pm

I didn't either! I expected to need to install something, but found a web post somewhere that mentioned that file does it.

Return to “Advanced users”