示例#1
0
 def __init__(self, file):
     mediainfo.ImageInfo.__init__(self)
     self.iptc = None
     self.mime = 'image/png'
     self.type = 'PNG image'
     self.valid = 1
     signature = file.read(8)
     if (signature != PNGSIGNATURE):
         self.valid = 0
         return
     self.meta = {}
     while self._readChunk(file):
         pass
     if len(self.meta.keys()):
         self.appendtable('PNGMETA', self.meta)
     for key, value in self.meta.items():
         if key.startswith('Thumb:') or key == 'Software':
             setattr(self, key, value)
             if not key in self.keys:
                 self.keys.append(key)
     ImageInfo.add(file.name, self)
     return
def getDatasetFromFile(path):


    '''
    读取数据库中图片,生成训练集和测试集特征点向量
    :param path: 数据库路径
    :return: 训练集特征点向量,测试集特征点向量

    '''
    dirs = os.listdir(path)

    imgTrainSet = []
    imgTestSet = []

    label = 0
    feature_set = np.float32([]).reshape(0, 128)
    for dir in dirs:
        files = os.listdir(path + "/" + dir)
        #files.remove("Thumbs.db")

        for i in range(150):
            img = cv2.imread(path + "/" + dir + "/" + files[i])
            img_info = ImageInfo.ImageInfo(img, label)
            img_info.getImgFeature()
            img_info.normalizeSIFT()
            imgTrainSet.append(img_info)
            feature_set = np.append(feature_set, img_info.descriptors, axis=0)

        for i in range(150, len(files)):
            img = cv2.imread(path + "/" + dir + "/" + files[i])
            img_info = ImageInfo.ImageInfo(img, label)
            img_info.getImgFeature()
            img_info.normalizeSIFT()
            imgTestSet.append(img_info)

        label += 1

    np.save("feature_set.npy", feature_set)
    return imgTrainSet, imgTestSet
示例#3
0
 def __init__(self, file):
     mediainfo.ImageInfo.__init__(self)
     self.iptc = None
     self.mime = "image/png"
     self.type = "PNG image"
     self.valid = 1
     signature = file.read(8)
     if signature != PNGSIGNATURE:
         self.valid = 0
         return
     self.meta = {}
     while self._readChunk(file):
         pass
     if len(self.meta.keys()):
         self.appendtable("PNGMETA", self.meta)
     for key, value in self.meta.items():
         if key.startswith("Thumb:") or key == "Software":
             setattr(self, key, value)
             if not key in self.keys:
                 self.keys.append(key)
     ImageInfo.add(file.name, self)
     return
示例#4
0
    def __init__(self,file):
        mediainfo.ImageInfo.__init__(self)
        iptc_info = None        
        self.mime = 'image/jpeg'
        self.type = 'jpeg image'
        self.valid = 1
        if file.read(2) != '\xff\xd8':
            self.valid = 0
            return
        file.seek(-2,2)
        if file.read(2) != '\xff\xd9':
            # Normally an JPEG should end in ffd9. This does not however
            # we assume it's an jpeg for now
            mediainfo._debug("Wrong encode found for jpeg")
        file.seek(2)
        app = file.read(4)
        self.meta = {}
        while (len(app) == 4):
            (ff,segtype,seglen) = struct.unpack(">BBH", app)
            if ff != 0xff: break
            _debug("SEGMENT: 0x%x%x, len=%d" % (ff,segtype,seglen))
            if segtype == 0xd9:
                break
            elif SOF.has_key(segtype):
                data = file.read(seglen-2)
                (precision,self.height,self.width,num_comp) = struct.unpack('>BHHB', data[:6])
                #_debug("H/W: %i / %i" % (self.height, self.width))
            elif segtype == 0xed:
                app = file.read(seglen-2)
                iptc_info = IPTC.flatten(IPTC.parseiptc(app))
                break
            elif segtype == 0xe7:
                # information created by libs like epeg
                data = file.read(seglen-2)
                if data.count('\n') == 1:
                    key, value = data.split('\n')
                    self.meta[key] = value
            else:
                file.seek(seglen-2,1)
            app = file.read(4)
        file.seek(0)
        exif_info = EXIF.process_file(file)
        if exif_info:
            self.setitem( 'date', exif_info, 'Image DateTime', True )            
            self.setitem( 'artist', exif_info, 'Image Artist', True )
            self.setitem( 'hardware', exif_info, 'Image Model', True )
            self.setitem( 'software', exif_info, 'Image Software', True )
            self.setitem( 'thumbnail', exif_info, 'JPEGThumbnail', True )
            self.appendtable( 'EXIF', exif_info )
        if iptc_info:
            self.setitem( 'title', iptc_info, 517, True ) 
            self.setitem( 'date' , iptc_info, 567, True )
            self.setitem( 'comment', iptc_info, 617, True )
            self.setitem( 'keywords', iptc_info, 537, True )
            self.setitem( 'artist', iptc_info, 592, True )
            self.setitem( 'country', iptc_info, 612, True ) 
            self.setitem( 'caption', iptc_info, 632, True )
            self.appendtable( 'IPTC', iptc_info )            

        if len(self.meta.keys()):
            self.appendtable( 'JPGMETA', self.meta )
        for key, value in self.meta.items():
            if key.startswith('Thumb:') or key == 'Software':
                setattr(self, key, value)
                if not key in self.keys:
                    self.keys.append(key)

        ImageInfo.add(file.name, self)
        return
示例#5
0
                "tgt_name":"", "tgt_exif":"", "tgt_created":"", "tgt_modified":"", "tgt_accessed":""}
 # file_info = {}
 ignore = "N"
 log_msg = ""
 log_level = "info"
 f_name = os.path.splitext(f)[0]
 f_ext = os.path.splitext(f)[1]
 f_file = f
 f_path = os.path.join(path, f_file)
 # file type
 if os.path.isfile(os.path.join(path, f_file)):
     # media file type
     if allowed_file.count(f_ext.upper()) > 0:
         file_info["src_name"] = f_file  # add file info
         # exif_date = ""
         f_str_date, f_name_new = ImageInfo.get_format_date(f_name)    #YYYY-MM-DD 24H:MI:SS, YYYYMMDD_24HMISS
         file_info["src_date"] = f_str_date  # add file info
         f_file_new = f_name_new + f_ext
         # file_info["tgt_name"] = f_file_new  # add file info
         print
         print "File Name: %s" % f_file
         print "File Date : %s (YYYY-MM-DD HH:Mi:SS)" % (f_str_date)
         log_msg += "\n" \
                    "File Name: %s\n" \
                    "File Date: %s (YYYY-MM-DD HH:Mi:SS)\n" % (f_file, f_str_date)
         # jpg format type
         if f_ext.upper() == ".JPG" or f_ext.upper() == ".JPEG":
             exif_date = ImageInfo.get_exif(os.path.join(path, f_file))
             e_str_date, e_name_new = ImageInfo.get_format_date(exif_date) #YYYY-MM-DD 24H:MI:SS, YYYYMMDD_24HMISS
             file_info["src_exif"] = e_str_date  # add file info
             e_file_new = e_name_new + f_ext
示例#6
0
    def __init__(self, file):
        mediainfo.ImageInfo.__init__(self)
        iptc_info = None
        self.mime = 'image/jpeg'
        self.type = 'jpeg image'
        self.valid = 1
        if file.read(2) != '\xff\xd8':
            self.valid = 0
            return
        file.seek(-2, 2)
        if file.read(2) != '\xff\xd9':
            # Normally an JPEG should end in ffd9. This does not however
            # we assume it's an jpeg for now
            mediainfo._debug("Wrong encode found for jpeg")
        file.seek(2)
        app = file.read(4)
        self.meta = {}
        while (len(app) == 4):
            (ff, segtype, seglen) = struct.unpack(">BBH", app)
            if ff != 0xff: break
            _debug("SEGMENT: 0x%x%x, len=%d" % (ff, segtype, seglen))
            if segtype == 0xd9:
                break
            elif SOF.has_key(segtype):
                data = file.read(seglen - 2)
                (precision, self.height, self.width,
                 num_comp) = struct.unpack('>BHHB', data[:6])
                #_debug("H/W: %i / %i" % (self.height, self.width))
            elif segtype == 0xed:
                app = file.read(seglen - 2)
                iptc_info = IPTC.flatten(IPTC.parseiptc(app))
                break
            elif segtype == 0xe7:
                # information created by libs like epeg
                data = file.read(seglen - 2)
                if data.count('\n') == 1:
                    key, value = data.split('\n')
                    self.meta[key] = value
            else:
                file.seek(seglen - 2, 1)
            app = file.read(4)
        file.seek(0)
        exif_info = EXIF.process_file(file)
        if exif_info:
            self.setitem('date', exif_info, 'Image DateTime', True)
            self.setitem('artist', exif_info, 'Image Artist', True)
            self.setitem('hardware', exif_info, 'Image Model', True)
            self.setitem('software', exif_info, 'Image Software', True)
            self.setitem('thumbnail', exif_info, 'JPEGThumbnail', True)
            self.appendtable('EXIF', exif_info)
        if iptc_info:
            self.setitem('title', iptc_info, 517, True)
            self.setitem('date', iptc_info, 567, True)
            self.setitem('comment', iptc_info, 617, True)
            self.setitem('keywords', iptc_info, 537, True)
            self.setitem('artist', iptc_info, 592, True)
            self.setitem('country', iptc_info, 612, True)
            self.setitem('caption', iptc_info, 632, True)
            self.appendtable('IPTC', iptc_info)

        if len(self.meta.keys()):
            self.appendtable('JPGMETA', self.meta)
        for key, value in self.meta.items():
            if key.startswith('Thumb:') or key == 'Software':
                setattr(self, key, value)
                if not key in self.keys:
                    self.keys.append(key)

        ImageInfo.add(file.name, self)
        return
示例#7
0
    def __init__(self,file):
        mediainfo.ImageInfo.__init__(self)
        self.iptc = None        
        self.mime = 'image/tiff'
        self.type = 'TIFF image'
        self.intel = 0
        self.valid = 0
        iptc = {}
        header = file.read(8)
        if header[:4] == MOTOROLASIGNATURE:
            self.valid = 1
            self.intel = 0
            (offset,) = struct.unpack(">I", header[4:8])
            file.seek(offset)
            (len,) = struct.unpack(">H", file.read(2))
            app = file.read(len*12)
            for i in range(len):
                (tag, type, length, value, offset) = struct.unpack('>HHIHH', app[i*12:i*12+12])
                _debug("[%i/%i] tag: 0x%.4x, type 0x%.4x, len %d, value %d, offset %d)" % (i,len,tag,type,length,value,offset))
                if tag == 0x8649:
                    file.seek(offset,0)
                    iptc = IPTC.flatten(IPTC.parseiptc(file.read(1000)))
                elif tag == 0x0100:
                    if value != 0:
                        self.width = value
                    else:
                        self.width = offset
                elif tag == 0x0101:
                    if value != 0:
                        self.height = value
                    else:
                        self.height = offset

        elif header[:4] == INTELSIGNATURE:
            self.valid = 1
            self.intel = 1
            (offset,) = struct.unpack("<I", header[4:8])
            file.seek(offset,0)
            (len,) = struct.unpack("<H", file.read(2))
            app = file.read(len*12)
            for i in range(len):
                (tag, type, length, offset, value) = struct.unpack('<HHIHH', app[i*12:i*12+12])
                _debug("[%i/%i] tag: 0x%.4x, type 0x%.4x, len %d, value %d, offset %d)" % (i,len,tag,type,length,value,offset))
                if tag == 0x8649:
                    file.seek(offset)
                    iptc = IPTC.flatten(IPTC.parseiptc(file.read(1000)))
                elif tag == 0x0100:
                    if value != 0:
                        self.width = value
                    else:
                        self.width = offset
                elif tag == 0x0101:
                    if value != 0:
                        self.height = value
                    else:
                        self.height = offset
        else:
            ImageInfo.add(file.name, self)
            return
            
        if iptc:
            self.setitem( 'title', iptc, 517 ) 
            self.setitem( 'date' , iptc, 567 )
            self.setitem( 'comment', iptc, 617 )
            self.setitem( 'keywords', iptc, 537 )
            self.setitem( 'artist', iptc, 592 )
            self.setitem( 'country', iptc, 612 ) 
            self.setitem( 'caption', iptc, 632 )
            self.appendtable('IPTC', iptc)

        ImageInfo.add(file.name, self)
        return