Blame view

mdata/helper.py 739 Bytes
1b6f5e02   Chunk   re-spidering
1
2
3
4
5
__author__ = 'hadoop'

from ..mfeat import HOG, IntraBlockDiff
import tempfile

e3e7e73a   Chunk   spider standalone...
6
def get_feat(image, feattype='ibd', frommem=False, **kwargs):
1b6f5e02   Chunk   re-spidering
7
    if  frommem:
e3e7e73a   Chunk   spider standalone...
8
9
        try:
            tmpf = tempfile.NamedTemporaryFile(suffix='.jpg', mode='w+b')
1b6f5e02   Chunk   re-spidering
10
11
12
13
14
            tmpf.write(image)
            tmpf.seek(0)
            image = tmpf.name
        except Exception as e:
            print e
e3e7e73a   Chunk   spider standalone...
15
16
17
18
19
20
21
22
23
            raise
        finally:
            tmpf.close()

    size = kwargs.get('size', (48, 48))

    if feattype == 'hog':
        feater = HOG.FeatHOG(size=size)
    elif feattype == 'ibd':
1b6f5e02   Chunk   re-spidering
24
25
26
27
28
29
        feater = IntraBlockDiff.FeatIntraBlockDiff()
    else:
        raise Exception("Unknown feature type!")

    desc = feater.feat(image)

1b6f5e02   Chunk   re-spidering
30
    return desc
e3e7e73a   Chunk   spider standalone...

1b6f5e02   Chunk   re-spidering