コード例 #1
0
    def scanPic(self, uri):
        mr = MediaResource(graph, uri)
        jpg, mtime = mr.getImageAndMtime(1000)
        mat = cv.CreateMatHeader(1, len(jpg), cv.CV_8UC1)
        cv.SetData(mat, jpg, len(jpg))
        img = cv.DecodeImage(mat)

        grayscale = cv.CreateImage((img.width, img.height), 8, 1)
        cv.CvtColor(img, grayscale, cv.CV_RGB2GRAY)

        cv.EqualizeHist(grayscale, grayscale)

        storage = cv.CreateMemStorage(0)
        faces = cv.HaarDetectObjects(
            grayscale,
            self.cascade,
            storage,
            1.2,  # scaleFactor between scans
            3,  # minNeighbors
            cv.CV_HAAR_DO_CANNY_PRUNING,
            (20, 20)  # min window size
        )
        size = cv.GetSize(grayscale)

        for f, neighbors in faces:
            desc = {
                'source': str(uri),
                'types': [PHO.Crop],
                'tag': 'face',
                'x1': f[0] / size[0],
                'y1': f[1] / size[1],
                'x2': (f[0] + f[2]) / size[0],
                'y2': (f[1] + f[3]) / size[1],

                # this ought to have a padded version for showing, and
                # also the face coords inside that padded version, for
                # recognition. Note that the padded one may run into
                # the margins
                'neighbors': neighbors,
            }

            alt = restkit.Resource(
                uri.replace('http://photo.bigasterisk.com/',
                            'http://bang:8031/') + "/alt")
            resp = alt.post(payload=json.dumps(desc),
                            headers={
                                'content-type':
                                'application/json',
                                'x-foaf-agent':
                                'http://bigasterisk.com/tool/scanFace'
                            })
            print resp.status, resp.body_string()
コード例 #2
0
ファイル: scanFace.py プロジェクト: drewp/photo
    def scanPic(self, uri):
        mr = MediaResource(graph, uri)
        jpg, mtime = mr.getImageAndMtime(1000)
        mat = cv.CreateMatHeader(1, len(jpg), cv.CV_8UC1)
        cv.SetData(mat, jpg, len(jpg))
        img = cv.DecodeImage(mat)

        grayscale = cv.CreateImage((img.width, img.height), 8, 1)
        cv.CvtColor(img, grayscale, cv.CV_RGB2GRAY)

        cv.EqualizeHist(grayscale, grayscale)

        storage = cv.CreateMemStorage(0)
        faces = cv.HaarDetectObjects(
            grayscale,
            self.cascade,
            storage,
            1.2,  # scaleFactor between scans
            3,  # minNeighbors
            cv.CV_HAAR_DO_CANNY_PRUNING,
            (20, 20),  # min window size
        )
        size = cv.GetSize(grayscale)

        for f, neighbors in faces:
            desc = {
                "source": str(uri),
                "types": [PHO.Crop],
                "tag": "face",
                "x1": f[0] / size[0],
                "y1": f[1] / size[1],
                "x2": (f[0] + f[2]) / size[0],
                "y2": (f[1] + f[3]) / size[1],
                # this ought to have a padded version for showing, and
                # also the face coords inside that padded version, for
                # recognition. Note that the padded one may run into
                # the margins
                "neighbors": neighbors,
            }

            alt = restkit.Resource(uri.replace("http://photo.bigasterisk.com/", "http://bang:8031/") + "/alt")
            resp = alt.post(
                payload=json.dumps(desc),
                headers={"content-type": "application/json", "x-foaf-agent": "http://bigasterisk.com/tool/scanFace"},
            )
            print resp.status, resp.body_string()
コード例 #3
0
    def imageResource(self, uri, ctx, t1, t2):
        r = MediaResource(graph, uri)
        size = getRequestedSize(ctx)
        useMp4 = ctx.arg('type') == 'mp4'
        jpg, mtime = r.getImageAndMtime(size, useMp4=useMp4)

        if r.isVideo():
            if size is Video2:
                if useMp4:
                    ct = 'video/mp4'
                else:
                    ct = 'video/webm'
            else:
                ct = 'application/binary'
        else:
            ct = 'image/jpeg'
        if uri.endswith('webm'):
            ct = 'video/webm'
        return StaticCached(jpg, ct, mtime, t1, t2)
コード例 #4
0
ファイル: mediaServe.py プロジェクト: drewp/photo
    def imageResource(self, uri, ctx, t1, t2):
        r = MediaResource(graph, uri)
        size = getRequestedSize(ctx)
        useMp4 = ctx.arg('type') == 'mp4'
        jpg, mtime = r.getImageAndMtime(size, useMp4=useMp4)

        if r.isVideo():
            if size is Video2:
                if useMp4:
                    ct = 'video/mp4'
                else:
                    ct = 'video/webm'
            else:
                ct = 'application/binary'
        else:
            ct = 'image/jpeg'
        if uri.endswith('webm'):
            ct = 'video/webm'
        return StaticCached(jpg, ct, mtime, t1, t2)