
Subir imagenes desde PYTHON
Publicado por Ramon (1 intervención) el 06/04/2016 22:01:35
hola
Estoy trabajando en subir fotos desde una apps web. pero antes de bajarla debo procesar la imagen y mostrarla. todo el proceso de imagen tengo codigo python funciona con dandole manualmente el path de la fotografia. eh intentado con sin numero de option hasta hora sin ningun framework.
codigo html is
codigo python
Muchas gracias por lo que quieran colaborarme
thank you
Estoy trabajando en subir fotos desde una apps web. pero antes de bajarla debo procesar la imagen y mostrarla. todo el proceso de imagen tengo codigo python funciona con dandole manualmente el path de la fotografia. eh intentado con sin numero de option hasta hora sin ningun framework.
codigo html is
1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html>
<body>
<form enctype="multipart/form-data"
action="imgproc/scan.py" method="post">
<p>File: <input type="file" name="filename" /></p>
<p><input type="submit" value="Upload" /></p>
</form>
</body>
</html>
codigo python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# USAGE
# python scan.py --image images/page.jpg
# import the necessary packages
from pyimagesearch.transform import four_point_transform
from pyimagesearch import imutils
# from skimage.filters import threshold_adaptive
import numpy as np
import argparse
import cv2
# import urllib
# import urllib2
import requests
import cgi
import cgitb; cgitb.enable()
import os, sys
import shutil
# data = cgi.FieldStorage();
# fileitem = data["filename"]
# filepath = os.getcwd()
# im = open(filename, "r+b")
# print("Content-Type: text/plain;charset=utf-8")
# form = cgi.FieldStorage()
# fileitem = form['filename']
image = cv2.imread('foto.jpg')
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)
# convert the image to grayscale, blur it, and find edges
# in the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 75, 200)
(_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_TC89_KCOS)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
# loop over the contours
for c in cnts:
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4:
screenCnt = approx
break
cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
warped = four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)
cv2.imwrite('fotosalida', warped)
Muchas gracias por lo que quieran colaborarme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# USAGE
# python scan.py --image images/page.jpg
# import the necessary packages
from pyimagesearch.transform import four_point_transform
from pyimagesearch import imutils
# from skimage.filters import threshold_adaptive
import numpy as np
import argparse
import cv2
# import urllib
# import urllib2
import requests
import cgi
import cgitb; cgitb.enable()
import os, sys
import shutil
# data = cgi.FieldStorage();
# fileitem = data["filename"]
# filepath = os.getcwd()
# im = open(filename, "r+b")
# print("Content-Type: text/plain;charset=utf-8")
# form = cgi.FieldStorage()
# fileitem = form['filename']
image = cv2.imread('foto.jpg')
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)
# convert the image to grayscale, blur it, and find edges
# in the image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 75, 200)
(_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_TC89_KCOS)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]
# loop over the contours
for c in cnts:
# approximate the contour
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.02 * peri, True)
if len(approx) == 4:
screenCnt = approx
break
cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2)
warped = four_point_transform(orig, screenCnt.reshape(4, 2) * ratio)
cv2.imwrite('fotosalida', warped)
Valora esta pregunta


0