|
|
|
|
@ -180,7 +180,9 @@ def hsv_color_space(request, color):
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def logic_and(img, has_color):
|
|
|
|
|
def logic_and(img, has_color, base):
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
@ -191,7 +193,9 @@ def logic_and(img, has_color):
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def logic_or(img, has_color):
|
|
|
|
|
def logic_or(img, has_color, base):
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
@ -202,7 +206,9 @@ def logic_or(img, has_color):
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def logic_not(img, has_color):
|
|
|
|
|
def logic_not(img, has_color, base):
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
image = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
ret = ~image
|
|
|
|
|
filename = getImageName() + '.jpg'
|
|
|
|
|
@ -210,22 +216,84 @@ def logic_not(img, has_color):
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def arithmetic_add(img, has_color, base):
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
img2 = cv2.resize(img2, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
ret = cv2.add(img1, img2)
|
|
|
|
|
filename = getImageName() + '.jpg'
|
|
|
|
|
cv2.imwrite(PREFIX + filename, ret)
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def arithmetic_sub(img, has_color, base):
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
if base == 1:
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
img2 = cv2.resize(img2, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
elif base == 2:
|
|
|
|
|
rows, cols = img2.shape[:2]
|
|
|
|
|
img1 = cv2.resize(img1, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
ret = cv2.subtract(img1, img2)
|
|
|
|
|
filename = getImageName() + '.jpg'
|
|
|
|
|
cv2.imwrite(PREFIX + filename, ret)
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def arithmetic_multi(img, has_color, base):
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
img2 = cv2.resize(img2, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
ret = cv2.multiply(img1, img2)
|
|
|
|
|
filename = getImageName() + '.jpg'
|
|
|
|
|
cv2.imwrite(PREFIX + filename, ret)
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def arithmetic_div(img, has_color, base):
|
|
|
|
|
img1 = cv2.imread(PREFIX + img[0], has_color)
|
|
|
|
|
img2 = cv2.imread(PREFIX + img[1], has_color)
|
|
|
|
|
if base == 1:
|
|
|
|
|
rows, cols = img1.shape[:2]
|
|
|
|
|
img2 = cv2.resize(img2, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
elif base == 2:
|
|
|
|
|
rows, cols = img2.shape[:2]
|
|
|
|
|
img1 = cv2.resize(img1, (cols, rows), interpolation=cv2.INTER_CUBIC)
|
|
|
|
|
ret = cv2.divide(img1, img2)
|
|
|
|
|
filename = getImageName() + '.jpg'
|
|
|
|
|
cv2.imwrite(PREFIX + filename, ret)
|
|
|
|
|
return filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
|
def logic_operation(request):
|
|
|
|
|
def basic_operation(request):
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
para = json.loads(request.body)
|
|
|
|
|
operator = para['operator']
|
|
|
|
|
img = para['img']
|
|
|
|
|
has_color = para['color']
|
|
|
|
|
base = para['base']
|
|
|
|
|
if base == 2:
|
|
|
|
|
img[0], img[1] = img[1], img[0]
|
|
|
|
|
if operator == 'and':
|
|
|
|
|
return HttpResponse(logic_and(img, has_color))
|
|
|
|
|
return HttpResponse(logic_and(img, has_color, base))
|
|
|
|
|
elif operator == 'or':
|
|
|
|
|
return HttpResponse(logic_or(img, has_color))
|
|
|
|
|
return HttpResponse(logic_or(img, has_color, base))
|
|
|
|
|
elif operator == 'not':
|
|
|
|
|
return HttpResponse(logic_not(img, has_color))
|
|
|
|
|
return HttpResponse(logic_not(img, has_color, base))
|
|
|
|
|
elif operator == 'add':
|
|
|
|
|
return HttpResponse(arithmetic_add(img, has_color, base))
|
|
|
|
|
elif operator == 'sub':
|
|
|
|
|
return HttpResponse(arithmetic_sub(img, has_color, base))
|
|
|
|
|
elif operator == 'multi':
|
|
|
|
|
return HttpResponse(arithmetic_multi(img, has_color, base))
|
|
|
|
|
elif operator == 'div':
|
|
|
|
|
return HttpResponse(arithmetic_div(img, has_color, base))
|
|
|
|
|
return HttpResponse('请使用POST方法')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|