From a5ab2b9e47e57b71a5e099d45bc1c65fbe66596c Mon Sep 17 00:00:00 2001 From: charlie <1753524606@qq.com> Date: Wed, 20 Jul 2022 20:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BB=BF=E5=B0=84=E5=8F=98?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- basic/urls.py | 3 ++- basic/views.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/basic/urls.py b/basic/urls.py index 22a0647..cbec77b 100644 --- a/basic/urls.py +++ b/basic/urls.py @@ -12,5 +12,6 @@ urlpatterns = [ path('resize', views.resize), path('rotate', views.rotate), path('translation', views.translation), - path('flip', views.flip) + path('flip', views.flip), + path('affine', views.affine), ] diff --git a/basic/views.py b/basic/views.py index 5bbc58a..dfd913a 100644 --- a/basic/views.py +++ b/basic/views.py @@ -385,5 +385,22 @@ def flip(request): return HttpResponse('请使用POST方法') +@csrf_exempt +def affine(request): + if request.method == 'POST': + para = json.loads(request.body) + image = para['img'] + img = cv2.imread(PREFIX + image) + before = np.float32(para['before']) + after = np.float32(para['after']) + rows, cols = img.shape[:2] + M = cv2.getAffineTransform(before, after) + img = cv2.warpAffine(img, M, (rows, cols)) + filename = getImageName() + DEFAULT_FORMAT + cv2.imwrite(PREFIX + filename, img) + return HttpResponse(filename) + return HttpResponse('请使用POST方法') + + def r(request): return render(request, 'upload.html')