2017-12-27 8 views
0

내 파이썬 함수로 인해 뷰티 파이썬에서 사용자가 선택한 이미지의 URL을 전달하려고합니다. 사용자가 선택한 이미지를 처리합니다. 이것은 나의 HTML 명령내 HTML 파일에 클릭 한 이미지의 URL을 views.py 내 Python 함수에 전달하는 방법 Django

<!DOCTYPE html> 
<html> 
<head> 
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script> 
<meta charset=utf-8 /> 
<title>JS Bin</title> 
<!--[if IE]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
<style> 
    article, aside, figure, footer, header, hgroup, 
    menu, nav, section { display: block; } 
</style> 
</head> 
<body> 
    <input type='file' onchange="readURL(this);" /> 
    <img id="blah" src="#" alt="your image" /> 
<script> 
    function readURL(input) { 
     if (input.files && input.files[0]) { 
      var reader = new FileReader(); 

      reader.onload = function (e) { 
       $('#blah') 
        .attr('src', e.target.result) 
        .width(150) 
        .height(200); 
      }; 

      reader.readAsDataURL(input.files[0]); 
     } 
    } 
</script> 
</body> 
</html> 

이며, 여기에 내가 어떻게 할 수 있습니다) (cv2.imread에 있어야 사용자가 선택한 내 파이썬

def predict(): 
    img = cv2.imread('C:/Users/HABITUS/Desktop/arvin files/download.jpg') #the url of the image selected must be here!! 
    img = cv2.resize(img, (600, 600)) 
    enhancer = Image.fromarray(img) 
    enhancer = ImageEnhance.Contrast(enhancer) 
    enhanced = enhancer.enhance(1.5) 
    enhancer1 = ImageEnhance.Brightness(enhanced).enhance(1.3) 
    convert = scipy.misc.fromimage(enhancer1) 
    imgM = cv2.medianBlur(convert, 5) 
    # blurring and smoothening 
    kernel = np.ones((5, 5), np.uint8) 
    erosion = cv2.erode(imgM, kernel, iterations=1) 
    dilation = cv2.dilate(erosion, kernel, iterations=1) 
    blur = cv2.GaussianBlur(convert, (15, 15), 10) 
    grayscaled = cv2.cvtColor(imgM, cv2.COLOR_BGR2GRAY) 

    retval2, threshold2 = cv2.threshold(grayscaled, 200, 1, cv2.THRESH_BINARY_INV) 

    gaus = cv2.adaptiveThreshold(grayscaled, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 115, 1) 
    retval2, otsu = cv2.threshold(grayscaled, 140, 250, cv2.THRESH_BINARY + cv2.THRESH_OTSU) 
    backtorgb = cv2.cvtColor(threshold2, cv2.COLOR_GRAY2RGB) 
    mult = cv2.multiply(img, backtorgb) 
    edges = cv2.Canny(threshold2, 120, 50) 

이미지의 기능은 무엇입니까? 어떤 조언이나 도움을 주셔서 감사합니다

+0

내가 아니 Django 2.0을 아직 읽지 않았습니다. 하지만 이것은 장고에서 정말 좋은 질문입니다. 내 생각에 당신이 설명하는 유스 케이스는 프런트 엔드와 백엔드로 나뉘어져있다. 이것은 약간의 불일치가있을 것이라고 확신하지만 장고는 장고가 JS와 대화하기위한 프레임 워크를 명시 적으로 명확히하지 않습니다. 그래서 빠르고 더러운 단지 장고 양식을 사용하십시오. 하지만 더 많은 프로덕션 유스 케이스의 경우 js 프레임 워크를 사용하여 img가 onClicked인지 청취 한 다음 django rest 프레임 워크 엔드 포인트에 게시해야합니다. – sahutchi

답변

관련 문제