0

I am trying to upload .xml file(approx size 2MB) from the browser(html). Using python(cv2) am trying to read the haarcscade.xml from the python code. 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

The following the code snapshot:

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] 

I tried with the link but i was not able to fix the issue.

1 Answers1

0

Try saving the file locally on the server with file.save("path/to/file") and then open it for read with open("path/to/file", "r").

darksky
  • 1,955
  • 16
  • 28
  • Storing every file in temp location would be tedious job since i have user concurrency around 1k. Any other option where i can read the files directly from the browser. – Avinaash Gollapudi Jun 30 '17 at 14:34
  • Well, you don't have to store it permanently. Store it, read it, parse, it, and when you are done with the file `os.remove("/path/to/file")` will delete it. – darksky Jun 30 '17 at 20:27