简体   繁体   English

函数cvMemStorageAlloc中请求的python server.py错误大小为负数或太大

[英]python server.py error requested size is negative or too big in function cvMemStorageAlloc

I am trying to upload .xml file(approx size 2MB) from the browser(html). 我正在尝试从浏览器(html)上传.xml文件(大约2MB)。 Using python(cv2) am trying to read the haarcscade.xml from the python code. 使用python(cv2)试图从python代码读取haarcscade.xml。 we are getting following error 我们收到以下错误

error: /hom1e/administrator/openface/opencv-3.0.0/modules/core/src/datastructs.cpp:338: error: (-211) requested size is negative or too big in function cvMemStorageAlloc 错误:/hom1e/administrator/openface/opencv-3.0.0/modules/core/src/datastructs.cpp:338:错误:(-211)请求的大小为负或函数cvMemStorageAlloc中太大

The following the code snapshot: 下面的代码快照:

server.py 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 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] 

I tried with the link but i was not able to fix the issue. 我尝试了链接,但无法解决该问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM