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')