python server.py错误请求的大小在函数cvMemStorageAlloc

时间:2017-06-29 12:49:20

标签: python opencv flask

我正在尝试从浏览器(html)上传.xml文件(大约2MB)。使用python(cv2)我试图从python代码中读取haarcscade.xml。我们收到了以下错误

错误:/hom1e/administrator/openface/opencv-3.0.0/modules/core/src/datastructs.cpp:338:错误:( - 211)请求的大小在函数cvMemStorageAlloc中是负数还是太大

以下代码快照:

server.py

    from flask import Flask, render_template, json, request

    from flask import Flask, request, redirect, url_for

    import os

    from faceObject import facedetection

    from pathlib import Path

    app = Flask(__name__)

    c1 = facedetection()

    @app.route('/')
    def hello_world():
        return render_template('index.html')

    @app.route('/uploader', methods = ['GET', 'POST'])
    def upload_file():
        if request.method == 'POST':
            f = request.files['file']
            c1.getfaceCoordinates(f.read())
            f.save(secure_filename(f.filename))

    if __name__ == '__main__': # running on port 5000
          app.run(debug=True,host='0.0.0.0')

faceObject.py

import numpy as np

import sys

import boto3

import os

from boto.s3.key import Key

from botocore.client import Config

import os

import cv2

import imageio

class facedetection(object):

    def getfaceCoordinates (self, value):

        faceCascade = cv2.CascadeClassifier(value)
        vid = imageio.get_reader('test.mp4',  'ffmpeg')

        for i, im in enumerate(vid):

            print ('....',i)

            image = vid.get_data(i)

            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

            faces = faceCascade.detectMultiScale(gray, 1.3, 5) 

        for (x,y,w,h) in faces:
            print ('...detected faces...........') 
            cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2) 
            roi_gray = image[y:y+h, x:x+w] 

我尝试使用link,但我无法解决问题。

1 个答案:

答案 0 :(得分:0)

尝试使用file.save("path/to/file")在服务器上本地保存文件,然后将其打开以便使用open("path/to/file", "r")进行阅读。