-1

我使用谷歌应用引擎和 html5 创建了一个网页(其中嵌入了一个视频)。有一个用于检测微笑的python代码。单击播放按钮时我应该怎么做才能调用python代码(即)当视频开始自动播放时,应该检测到观众的脸......下面给出了应用程序引擎代码……

    import webapp2

    class MainPage(webapp2.RequestHandler):
    def get(self):
     self.response.out.write("""<!DOCTYPE html>
            <html>          
            <body>  
            <video width="320" height="240" controls>
            <source src="/video/mov_bbb.mp4" type="video/mp4">
            <source src="/video/mov_bbb.ogg" type="video/ogg">
             Your browser does not support the video tag.
            </video>
            </body>
            </html>""")

    app = webapp2.WSGIApplication([('/', MainPage)])

app.yaml 文件是....

    application: video
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: true

    handlers:
    - url: /video
     static_dir: video

    - url: /.*
    script: video.app

    - url: /(.*\.mp4)
    static_files: video/\1
    mime_type: video/mp4
    upload: video/(.*\.mp4)

    - url: /(.*\.ogg)
    static_files: video/\1
    mime_type: video/ogg
    upload: video/(.*\.ogv)

用于微笑检测的python代码是......

    import cv

    HAAR_CASCADE_PATH = "haarcascade_smile.xml"

    CAMERA_INDEX = 0

    def detect_faces(image):
             faces = []
             detected = cv.HaarDetectObjects(image, cascade, storage, 1.1,99,0,(40,40))
    if detected:
           for (x,y,w,h),n in detected:
                    faces.append((x,y,w,h))
           return faces

    if __name__ == "__main__":
            cv.NamedWindow("Video", cv.CV_WINDOW_AUTOSIZE)

            capture = cv.CaptureFromCAM(CAMERA_INDEX)
            storage = cv.CreateMemStorage()
            cascade = cv.Load(HAAR_CASCADE_PATH)

            faces = []

            i = 0
            c = -1
            while (c == -1):
                 image = cv.QueryFrame(capture)

                 #Only run the Detection algorithm every 5 frames to improve performance
                 if i%5==0:
                       faces = detect_faces(image)

                 for (x,y,w,h) in faces:
                       cv.Rectangle(image, (x,y), (x+w,y+h), 255)

                 cv.ShowImage("Video", image)   
                 i += 1
                 c = cv.WaitKey(10)
4

1 回答 1

1

你可能做不到。

视频将流式传输到客户端浏览器并在客户端浏览器上播放。由于它在浏览器中运行,因此您需要在浏览器中运行您的微笑检测代码。它必须通过javascript而不是python。

于 2013-05-04T18:58:02.540 回答