image - 如何使用 C++ 或 Python 从图像中读取图像描述?

标签 image opencv

我希望使用 C++ 或 Python 从图像属性选项卡(右键单击)读取图像描述文本。

enter image description here

有办法吗? 我猜 Opencv 似乎不支持它。 顺便说一句,我的操作系统是 ubuntu 16.04。

谢谢,

最佳答案

如果您使用的是 Ubuntu,您可能已经安装了 ImageMagick 并且在套件中有一个名为 identify 的程序。您可以在命令行的终端中运行以下命令,或者您可以运行 Python 子进程并获取其输出:

identify -verbose someImage.jpg

示例输出

Image: /Users/mark/Desktop/IMG_2326.JPG
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Mime type: image/jpeg
  Class: DirectClass
  Geometry: 3264x2448+0+0
  Resolution: 72x72
  Print size: 45.3333x34
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    Red: 8-bit
    Green: 8-bit
    Blue: 8-bit
  Channel statistics:
    Pixels: 7990272
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 139.125 (0.545587)
      standard deviation: 62.0934 (0.243503)
      kurtosis: -0.948773
      skewness: -0.255567
      entropy: 0.980761
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 129.827 (0.509124)
      standard deviation: 63.4802 (0.248942)
      kurtosis: -0.744472
      skewness: -0.322559
      entropy: 0.978628
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 121.768 (0.477522)
      standard deviation: 63.6425 (0.249578)
      kurtosis: -1.14208
      skewness: 0.0243162
      entropy: 0.980614
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 130.24 (0.510744)
      standard deviation: 63.4733 (0.248915)
      kurtosis: -0.968273
      skewness: -0.18575
      entropy: 0.980001
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 3264x2448+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 96
  Orientation: TopLeft
  Properties:
    date:create: 2017-05-31T13:53:16+01:00
    date:modify: 2014-09-23T08:22:25+01:00
    exif:ApertureValue: 4845/1918
    exif:BrightnessValue: 6155/1061
    exif:ColorSpace: 1
    exif:ComponentsConfiguration: 1, 2, 3, 0
    exif:DateTime: 2014:09:23 08:22:25
    exif:DateTimeDigitized: 2014:09:23 08:22:25
    exif:DateTimeOriginal: 2014:09:23 08:22:25
    exif:ExifImageLength: 2448
    exif:ExifImageWidth: 3264
    exif:ExifOffset: 204
    exif:ExifVersion: 48, 50, 50, 49
    exif:ExposureMode: 0
    exif:ExposureProgram: 2
    exif:ExposureTime: 1/120
    exif:Flash: 24
    exif:FlashPixVersion: 48, 49, 48, 48
    exif:FNumber: 12/5
    exif:FocalLength: 103/25
    exif:FocalLengthIn35mmFilm: 33
    exif:GPSAltitude: 10003/299
    exif:GPSAltitudeRef: 0
    exif:GPSInfo: 946
    exif:GPSLatitude: 51/1, 51/1, 347/100
    exif:GPSLatitudeRef: N
    exif:GPSLongitude: 2/1, 12/1, 1992/100
    exif:GPSLongitudeRef: W
    exif:GPSTimeStamp: 7/1, 22/1, 2456/100
    exif:ISOSpeedRatings: 64
    exif:Make: Apple
    exif:MakerNote: 65, 112, 112, 108, 101, 32, 105, 79, 83, 0, 0, 1, 77, 77, 0, 6, 0, 1, 0, 9, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3, 0, 7, 0, 0, 0, 104, 0, 0, 0, 92, 0, 4, 0, 9, 0, 0, 0, 1, 0, 0, 0, 1, 0, 5, 0, 9, 0, 0, 0, 1, 0, 0, 0, 208, 0, 6, 0, 9, 0, 0, 0, 1, 0, 0, 0, 218, 0, 7, 0, 9, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 98, 112, 108, 105, 115, 116, 48, 48, 212, 1, 2, 3, 4, 5, 6, 7, 8, 89, 116, 105, 109, 101, 115, 99, 97, 108, 101, 85, 101, 112, 111, 99, 104, 85, 118, 97, 108, 117, 101, 85, 102, 108, 97, 103, 115, 18, 59, 154, 202, 0, 16, 0, 19, 0, 0, 18, 143, 64, 67, 109, 189, 16, 1, 8, 17, 27, 33, 39, 45, 50, 52, 61, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63
    exif:MeteringMode: 5
    exif:Model: iPhone 5
    exif:Orientation: 1
    exif:ResolutionUnit: 2
    exif:SceneCaptureType: 0
    exif:SceneType: 1
    exif:SensingMethod: 2
    exif:ShutterSpeedValue: 5567/806
    exif:Software: 7.1.2
    exif:SubjectArea: 1631, 1223, 1795, 1077
    exif:SubSecTimeDigitized: 918
    exif:SubSecTimeOriginal: 918
    exif:thumbnail:Compression: 6
    exif:thumbnail:JPEGInterchangeFormat: 1210
    exif:thumbnail:JPEGInterchangeFormatLength: 12195
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:WhiteBalance: 0
    exif:XResolution: 72/1
    exif:YCbCrPositioning: 1
    exif:YResolution: 72/1
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: 84dc83ac4ff07920155036d321be9b8fe687be8b5eb68a76e20518b3e6f048f8
    unknown: 103/25, 103/25, 12/5, 12/5
  Profiles:
    Profile-exif: 16380 bytes
  Artifacts:
    verbose: true
  Tainted: False
  Filesize: 3.9071MiB
  Number pixels: 7.99027M
  Pixels per second: 47.0016MB
  User time: 0.150u
  Elapsed time: 0:01.170
  Version: ImageMagick 7.0.5-6 Q16 x86_64 2017-05-15 http://www.imagemagick.org

另一个选项是 exiftool,您可以在命令行中像这样运行它,也可以在 Python 中将其作为子进程运行:

exiftool ~/Desktop/IMG_2326.JPG 

示例输出

ExifTool Version Number         : 10.50
File Name                       : IMG_2326.JPG
Directory                       : /Users/mark/Desktop
File Size                       : 3.9 MB
File Modification Date/Time     : 2014:09:23 08:22:25+01:00
File Access Date/Time           : 2017:05:31 13:57:20+01:00
File Inode Change Date/Time     : 2017:05:31 13:53:16+01:00
File Permissions                : rw-------
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Big-endian (Motorola, MM)
Make                            : Apple
Camera Model Name               : iPhone 5
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : 7.1.2
Modify Date                     : 2014:09:23 08:22:25
Y Cb Cr Positioning             : Centered
Exposure Time                   : 1/120
F Number                        : 2.4
Exposure Program                : Program AE
ISO                             : 64
Exif Version                    : 0221
Date/Time Original              : 2014:09:23 08:22:25
Create Date                     : 2014:09:23 08:22:25
Components Configuration        : Y, Cb, Cr, -
Shutter Speed Value             : 1/120
Aperture Value                  : 2.4
Brightness Value                : 5.801131008
Metering Mode                   : Multi-segment
Flash                           : Auto, Did not fire
Focal Length                    : 4.1 mm
Subject Area                    : 1631 1223 1795 1077
Run Time Scale                  : 1000000000
Run Time Epoch                  : 0
Run Time Value                  : 20406467784125
Run Time Flags                  : Valid
Sub Sec Time Original           : 918
Sub Sec Time Digitized          : 918
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 3264
Exif Image Height               : 2448
Sensing Method                  : One-chip color area
Scene Type                      : Directly photographed
Exposure Mode                   : Auto
White Balance                   : Auto
Focal Length In 35mm Format     : 33 mm
Scene Capture Type              : Standard
Lens Info                       : 4.12mm f/2.4
Lens Make                       : Apple
Lens Model                      : iPhone 5 back camera 4.12mm f/2.4
GPS Latitude Ref                : North
GPS Longitude Ref               : West
GPS Altitude Ref                : Above Sea Level
GPS Time Stamp                  : 07:22:24.56
Compression                     : JPEG (old-style)
Thumbnail Offset                : 1222
Thumbnail Length                : 12195
Image Width                     : 3264
Image Height                    : 2448
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 2.4
GPS Altitude                    : 33.4 m Above Sea Level
GPS Latitude                    : 51 deg 51' 3.47" N
GPS Longitude                   : 2 deg 12' 19.92" W
GPS Position                    : 51 deg 51' 3.47" N, 2 deg 12' 19.92" W
Image Size                      : 3264x2448
Megapixels                      : 8.0
Run Time Since Power Up         : 5:40:06
Scale Factor To 35 mm Equivalent: 8.0
Shutter Speed                   : 1/120
Create Date                     : 2014:09:23 08:22:25.918
Date/Time Original              : 2014:09:23 08:22:25.918
Thumbnail Image                 : (Binary data 12195 bytes, use -b option to extract)
Circle Of Confusion             : 0.004 mm
Field Of View                   : 57.2 deg
Focal Length                    : 4.1 mm (35 mm equivalent: 33.0 mm)
Hyperfocal Distance             : 1.89 m
Light Value                     : 10.1

另一个选项是 exiv2,它可以从 here 获得,也有各种可用的库 API。

我没用过,不能认可,不过也有a Python interface to exiv2


如果你想了解 Python 子进程,你可以这样做:

import subprocess

...
...

p = subprocess.Popen(['identify -verbose someImage.jpg'], stdout=subprocess.PIPE)
retcode = p.wait()
data = p.stdout.read()

关于image - 如何使用 C++ 或 Python 从图像中读取图像描述?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44274658/

相关文章:

java - 为什么我拍摄了多次但应用程序只选择第一张照片进行处理

Javascript 图像预加载无法正常工作

c++ - Boost rng vs OpenCV rng vs c++11 std::random?

python - 如何将 `cv2.imwrite()` 输出到标准输出?

android - 使用opencv在android中抓取连续帧

javascript - 获取图像旋转 90、180 或 270 度后相对于原始图像的图像坐标

ios - GPUImage 组过滤器

css - 在 div 中均匀间隔 href img

python - 如何在开放式简历中与BGR图像像素值进行比较?

c++ - 使用 Hough OpenCV 时出错