0
我试图用python django模块构建一个web应用程序。任务是如果任何人去链接它将处理图像与阈值并保存到服务器文件夹。服务器端执行(执行后端图像处理)
我的代码是(views.py): -
from django.http import HttpResponse
import numpy as np
import cv2
import Image
from PIL import Image
import tesseract
import ctypes
import os
import ImageDraw
def index(request):
im_gray = cv2.imread('Rimage.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
(thresh, im_bw) = cv2.threshold(im_gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
thresh = 100
im_bw = cv2.threshold(im_gray, thresh, 255, cv2.THRESH_BINARY)[1]
cv2.imwrite('bw_image.png', im_bw)
return HttpResponse("Hello, world. You're at the polls index.")
这个代码是不能工作的错误: -
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
98. resolver_match = resolver.resolve(request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
343. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
372. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
366. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/meraj/Desktop/project/web/mysite/mysite/urls.py" in <module>
5. url(r'^polls/', include('polls.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
28. urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
File "/home/meraj/Desktop/project/web/mysite/polls/urls.py" in <module>
3. from polls import views
Exception Type: IndentationError at /polls/
Exception Value: unindent does not match any outer indentation level (views.py, line 20)
,因为它是本地执行没有什么错我的代码,但当我在Django框架上尝试时,它不工作。我的方向是否正确?我是python web框架的新手,所以我对此没有任何想法。在此先感谢
在Linux上。实际上,图片位于views.py所在的文件夹中。你可以告诉我所有的模块(numpy,图像,PIL,ctypes),如果我将它们放在views.py上,将会启动吗? @Wyrmwood – 2014-11-04 22:14:43
我不能与我拥有的信息。但是,该错误似乎是一个简单的IndentationError,所以更改导入可能无助于(此特定问题)。 – Wyrmwood 2014-11-04 22:29:36
numpy,Image,PIL,ctypes是那些导入django的工作? – 2014-11-04 22:35:48