How to add custom metadata to OpenCV/numpy image?


I have a question.

I am performing a series of operations (resize, copy, etc.) to some captured images in OpenCV, but I want to set some specific metadata (the attribute names should also be defined by me) to these images, which would survive those operations and can be extracted later on. I am not setting resolution values or any other value that changes after these operations. How can I do this? I heard of pyexiv2, but I have never seen any example involving OpenCV.

Thanks in advance!

So, ultimately, you could just facade the 2 file contents (data and metadata) behind your own python class:

import cv 
import pyexiv2

class MyImage():

  _filename = None
  _data = None
  _metadata = None

  def __init__(self,fname):

    _filename = fname
    _data = cv.LoadImage(_filename)
    _metadata = pyexiv2.ImageMetadata(_filename)

  def addMeta(self,key,value):
    _metadata[key] = pyexiv2.ExifTag(key, value)

  def delMeta(self,delkey):
    newdict = {key: value for key, value in some_dict.items()
                if value is not delkey}

  def resize(self,newx,newy):
    tmpimage = cv.CreateMat(newy, newx, cv.CV_8UC3)
    _data = tmpimage
    try: # Set metadata tags to new size if exist!
      _metadata['Exif.Image.XResolution'] = newx
      _metadata['Exif.Image.YResolution'] = newy

  def save(self):
By : timlukins

This video can help you solving your question :)
By: admin