カメラ名・レンズ名を追加する

概要

こちらの続きです。Rustでカメラの本体とレンズの情報が取得できるようにしました

参考

Exif TAG( http://cachu.xrea.jp/perl/ExifTAG.html ) を参考に対象となるtagを知らべました。

コード

事前に meta.get_exif_tags でどんなタグがあるのかを調べて上記のサイトで調べてみた。なんかめちゃくちゃあるが、sonyがついてないものにしないと他の機種が来たときにデータが取れなくなるので、比較的先頭の方からみたら見つけられた。

Ok(["Exif.Image.DateTime", "Exif.Image.ExifTag", "Exif.Image.ImageDescription", "Exif.Image.Make", "Exif.Image.Model", "Exif.Image.Orientation", "Exif.Image.PrintImageMatching", "Exif.Image.ResolutionUnit", "Exif.Image.Software", "Exif.Image.XResolution", "Exif.Image.YCbCrPositioning", "Exif.Image.YResolution", "Exif.Iop.InteroperabilityIndex", "Exif.Iop.InteroperabilityVersion", "Exif.MakerNote.ByteOrder", "Exif.MakerNote.Offset", "Exif.Photo.0x9010", "Exif.Photo.0x9011", "Exif.Photo.0x9012", "Exif.Photo.BrightnessValue", "Exif.Photo.ColorSpace", "Exif.Photo.ComponentsConfiguration", "Exif.Photo.CompressedBitsPerPixel", "Exif.Photo.Contrast", "Exif.Photo.CustomRendered", "Exif.Photo.DateTimeDigitized", "Exif.Photo.DateTimeOriginal", "Exif.Photo.DigitalZoomRatio", "Exif.Photo.ExifVersion", "Exif.Photo.ExposureBiasValue", "Exif.Photo.ExposureMode", "Exif.Photo.ExposureProgram", "Exif.Photo.ExposureTime", "Exif.Photo.FNumber", "Exif.Photo.FileSource", "Exif.Photo.Flash", "Exif.Photo.FlashpixVersion", "Exif.Photo.FocalLength", "Exif.Photo.FocalLengthIn35mmFilm", "Exif.Photo.ISOSpeedRatings", "Exif.Photo.InteroperabilityTag", "Exif.Photo.LensModel", "Exif.Photo.LensSpecification", "Exif.Photo.LightSource", "Exif.Photo.MakerNote", "Exif.Photo.MaxApertureValue", "Exif.Photo.MeteringMode", "Exif.Photo.PixelXDimension", "Exif.Photo.PixelYDimension", "Exif.Photo.RecommendedExposureIndex", "Exif.Photo.Saturation", "Exif.Photo.SceneCaptureType", "Exif.Photo.SceneType", "Exif.Photo.SensitivityType", "Exif.Photo.Sharpness", "Exif.Photo.UserComment", "Exif.Photo.WhiteBalance", "Exif.Sony1.0x2000", "Exif.Sony1.0x2002", "Exif.Sony1.0x2003", "Exif.Sony1.0x2006", "Exif.Sony1.0x2007", "Exif.Sony1.0x2008", "Exif.Sony1.0x2009", "Exif.Sony1.0x200b", "Exif.Sony1.0x200c", "Exif.Sony1.0x200d", "Exif.Sony1.0x200e", "Exif.Sony1.0x200f", "Exif.Sony1.0x2010", "Exif.Sony1.0x2011", "Exif.Sony1.0x2012", "Exif.Sony1.0x2013", "Exif.Sony1.0x2014", "Exif.Sony1.0x2015", "Exif.Sony1.0x2016", "Exif.Sony1.0x2017", "Exif.Sony1.0x2018", "Exif.Sony1.0x2019", "Exif.Sony1.0x201a", "Exif.Sony1.0x201b", "Exif.Sony1.0x201c", "Exif.Sony1.0x201d", "Exif.Sony1.0x201e", "Exif.Sony1.0x201f", "Exif.Sony1.0x2020", "Exif.Sony1.0x2021", "Exif.Sony1.0x2023", "Exif.Sony1.0x2025", "Exif.Sony1.0x2026", "Exif.Sony1.0x2027", "Exif.Sony1.0x2028", "Exif.Sony1.0x2029", "Exif.Sony1.0x202a", "Exif.Sony1.0x202b", "Exif.Sony1.0x202c", "Exif.Sony1.0x202d", "Exif.Sony1.0x202e", "Exif.Sony1.0x202f", "Exif.Sony1.0x5001", "Exif.Sony1.0x5002", "Exif.Sony1.0x9050", "Exif.Sony1.0x9400", "Exif.Sony1.0x9401", "Exif.Sony1.0x9402", "Exif.Sony1.0x9403", "Exif.Sony1.0x9404", "Exif.Sony1.0x9405", "Exif.Sony1.0x9406", "Exif.Sony1.0x9407", "Exif.Sony1.0x9408", "Exif.Sony1.0x9409", "Exif.Sony1.0x940a", "Exif.Sony1.0x940b", "Exif.Sony1.0x940c", "Exif.Sony1.0x940d", "Exif.Sony1.0x940e", "Exif.Sony1.0x940f", "Exif.Sony1.0x9412", "Exif.Sony1.0xa100", "Exif.Sony1.0xb02a", "Exif.Sony1.0xb045", "Exif.Sony1.0xb046", "Exif.Sony1.0xb04c", "Exif.Sony1.0xb04d", "Exif.Sony1.0xb050", "Exif.Sony1.0xb051", "Exif.Sony1.0xb053", "Exif.Sony1.AntiBlur", "Exif.Sony1.AutoHDR", "Exif.Sony1.ColorCompensationFilter", "Exif.Sony1.ColorMode", "Exif.Sony1.ColorReproduction", "Exif.Sony1.ColorTemperature", "Exif.Sony1.Contrast", "Exif.Sony1.DynamicRangeOptimizer", "Exif.Sony1.DynamicRangeOptimizer", "Exif.Sony1.ExposureMode", "Exif.Sony1.FileFormat", "Exif.Sony1.FlashExposureComp", "Exif.Sony1.FlashLevel", "Exif.Sony1.FullImageSize", "Exif.Sony1.ImageStabilization", "Exif.Sony1.IntelligentAuto", "Exif.Sony1.LensID", "Exif.Sony1.Panorama", "Exif.Sony1.PreviewImageSize", "Exif.Sony1.Quality", "Exif.Sony1.ReleaseMode", "Exif.Sony1.Saturation", "Exif.Sony1.SceneMode", "Exif.Sony1.SequenceNumber", "Exif.Sony1.ShotInfo", "Exif.Sony1.SonyModelID", "Exif.Sony1.WhiteBalance", "Exif.Sony1.WhiteBalance2", "Exif.Sony1.WhiteBalanceFineTune", "Exif.Sony1.ZoneMatching", "Exif.Thumbnail.Compression", "Exif.Thumbnail.DateTime", "Exif.Thumbnail.ImageDescription", "Exif.Thumbnail.JPEGInterchangeFormat", "Exif.Thumbnail.JPEGInterchangeFormatLength", "Exif.Thumbnail.Make", "Exif.Thumbnail.Model", "Exif.Thumbnail.Orientation", "Exif.Thumbnail.ResolutionUnit", "Exif.Thumbnail.Software", "Exif.Thumbnail.XResolution", "Exif.Thumbnail.YCbCrPositioning", "Exif.Thumbnail.YResolution"])

あとは meta.get_tag_string("Exif.Image.Model") などしてデータを取り出せばOK。

use std::env;
use rexiv2;

fn main() {
    let arguments = env::args().skip(1);
    for argument in arguments {
        let meta = rexiv2::Metadata::new_from_path(&argument).unwrap();

        println!("[{}]", argument);
        println!(
            "Body: {:?} / Lens: {:?} / F: {:?} / ISO: {:?} / Shutter: {:?}/{:?}",
            meta.get_tag_string("Exif.Image.Model").unwrap(),
            meta.get_tag_string("Exif.Photo.LensModel").unwrap(),
            meta.get_fnumber().unwrap(),
            meta.get_iso_speed().unwrap(),
            meta.get_exposure_time().unwrap().numer(), meta.get_exposure_time().unwrap().denom(),
        );
    }
}

CLIでの表示

[master]$ cargo run /Users/ryo/Downloads/Photos/DSC04117.jpg /Users/ryo/Downloads/DSCF1021.JPG
    Finished dev [unoptimized + debuginfo] target(s) in 0.33s                                                                       
     Running `target/debug/exif /Users/ryo/Downloads/Photos/DSC04117.jpg /Users/ryo/Downloads/DSCF1021.JPG`
[/Users/ryo/Downloads/Photos/DSC04117.jpg]
Body: "ILCE-7M3" / Lens: "FE 85mm F1.8" / F: 1.8 / ISO: 320 / Shutter: 1/200
[/Users/ryo/Downloads/DSCF1021.JPG]
Body: "X-M1" / Lens: "" / F: 0.0 / ISO: 1600 / Shutter: 1/100

という感じでレンズと機種名の表示ができるようになりました。(unwrap()してるところが怪しいのであとで見返さなければ行けないが異端おっけい)

Pocket

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください