Exemple #1
0
def upload_pic(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        imageName = str(request.FILES['image'])
        print "Hello this is :"+imageName
        # print request.POST
        if form.is_valid():
            m = ExampleModel()
            m.model_pic = form.cleaned_data['image']
            m.save()

            im = imClassify.imClassify()
            imagePath = 'utilities/images/'+imageName
            resultList = im.main(imagePath)
            print  "THi is view ;;;;;; ------ ;;;;"
            print resultList

            # Considering only the first string
            # [['giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca', 0.89233041], ['indri, indris, Indri indri, Indri brevicaudatus', 0.0085870409], ['lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens', 0.0026423461], ['custard apple', 0.0014067066], ['earthstar', 0.0010706335]]
            nameOfTopic = resultList[0][0].split(",")[0]
            print nameOfTopic

            du = duckduckGo.duckduckGo()
            description = du.getInfo(nameOfTopic)

            print description

            # Now deleting the file
            if os.path.isfile(imagePath):
                os.remove(imagePath)

            return render(request,'result.html',{'imageName':nameOfTopic, 'description':description})
    return HttpResponseForbidden('allowed only via POST')
Exemple #2
0
def upload_pic(request):
  
  c = {}
  c.update(csrf(request))  
  script_args['c'] = c
  
  if request.method == 'POST':
    form = ImageUploadForm(request.POST, request.FILES)
    if form.is_valid():
      m = ExampleModel()
      m.model_pic = form.cleaned_data['image']
      m.save()
      return HttpResponse('image upload success')
    
  return render_to_response("emc/upload_pic.html", c)    
Exemple #3
0
    def on_post(self, req, resp):
        email = req.get_json('email',
                             dtype=str,
                             min=6,
                             max=32,
                             default="*****@*****.**")
        name = req.get_json('name',
                            dtype=str,
                            min=1,
                            max=16,
                            default="Andrei Regiani")

        row = ExampleModel(email=email, name=name)
        row.save()

        resp.json = {'id': str(row.id)}
        resp.status = falcon.HTTP_201
Exemple #4
0
def upload_pic(request):

    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            # os.remove(file) for file in os.listdir('path/to/directory') if file.endswith('.png')
            for file in os.listdir(os.path.join(BASE_DIR, 'media', 'img')):
                if (file.endswith('.jpg')):
                    os.remove(os.path.join(BASE_DIR, 'media', 'img', file))
            for file in os.listdir(os.path.join(BASE_DIR, 'static', 'img')):
                if (file.endswith('.jpg')):
                    os.remove(os.path.join(BASE_DIR, 'static', 'img', file))
            m = ExampleModel()
            m.model_pic = form.cleaned_data['image']
            m.save()
            for file in os.listdir(os.path.join(BASE_DIR, 'media', 'img')):
                if (file.endswith('.jpg')):
                    shutil.move(
                        os.path.join(BASE_DIR, 'media', 'img', file),
                        os.path.join(BASE_DIR, 'media', 'img', 'main.jpg'))
                    shutil.copy(
                        os.path.join(BASE_DIR, 'media', 'img', 'main.jpg'),
                        os.path.join(BASE_DIR, 'static', 'img', 'main.jpg'))
            pathForImage = os.path.join(BASE_DIR, 'static', 'img', 'main.jpg')
            mainImage = cv2.imread(pathForImage)
            p = subprocess.Popen(
                '/usr/local/src/openalpr/src/build/alpr -c kz -p kz -j ' +
                pathForImage,
                stdout=subprocess.PIPE,
                shell=True)
            (output, err) = p.communicate()
            p_status = p.wait()
            main_out = output.split('\n')[0]
            data = (json.loads(main_out))['results']
            # print(data)
            if (len(data) == 0):
                data = {'plateNumber': 'НОМЕР БЫЛ НЕ НАЙДЕН'}
                return render(request, 'second.html', data)
            else:
                coordinates = data[0]['coordinates']
                top_left = coordinates[1]
                bottom_right = coordinates[3]
                y1 = top_left['y']
                x1 = top_left['x']

                y2 = bottom_right['y']
                x2 = bottom_right['x']

                cv2.rectangle(mainImage, (x1, int(y1)), (x2, int(y2)),
                              (0, 255, 0), 1)
                cv2.imwrite(pathForImage, mainImage)
                plates = data[0]['candidates']
                plate_number = (data[0]['candidates'][0]['plate'])

                best_predicted = data[0]['candidates'][0]['plate']
                best_predicted_by_pattern = []
                for plate in plates:
                    if (plate['matches_template'] == 1):
                        best_predicted_by_pattern.append(plate['plate'])
                if (len(best_predicted_by_pattern) != 0):
                    best_predicted = best_predicted_by_pattern[0]
                data = {'plateNumber': best_predicted}
                return render(request, 'second.html', data)
    return HttpResponseForbidden('allowed only via POST')