完成基础部分的测试

master
charlie 4 years ago
parent a0efc139fd
commit 03581c5616

@ -37,7 +37,8 @@ def process_bg():
def process_line(para):
name, start, end, color, thickness = para['img'], para['start'], para['end'], para['color'], para['thickness']
name, start, end, color, thickness = para['img'], para['start'], para['end'], \
para.get('color', [255, 255, 255]), para.get('thickness', 20)
img = cv2.imread(PREFIX + name)
cv2.line(img, tuple(start), tuple(end), tuple(color), thickness)
cv2.imwrite(PREFIX + name, img)
@ -45,7 +46,8 @@ def process_line(para):
def process_rectangle(para):
name, start, end, color, thickness = para['img'], para['start'], para['end'], para['color'], para['thickness']
name, start, end, color, thickness = para['img'], para['start'], para['end'], \
para.get('color', [255, 255, 255]), para.get('thickness', 20)
img = cv2.imread(PREFIX + name)
cv2.rectangle(img, tuple(start), tuple(end), tuple(color), thickness)
cv2.imwrite(PREFIX + name, img)
@ -53,8 +55,8 @@ def process_rectangle(para):
def process_circle(para):
name, center, radius, color, thickness = para['img'], para['center'], para['radius'], para['color'], para[
'thickness']
name, center, radius, color, thickness = para['img'], para['center'], para['radius'], \
para.get('color', [255, 255, 255]), para.get('thickness', 20)
img = cv2.imread(PREFIX + name)
cv2.circle(img, tuple(center), radius, tuple(color), thickness)
cv2.imwrite(PREFIX + name, img)
@ -62,8 +64,14 @@ def process_circle(para):
def process_ellipse(para):
name, center, axes, angle, startangle, endangle, color, thickness = para['img'], para['center'], para['axes'], para[
'angle'], para['startangle'], para['endangle'], para['color'], para['thickness']
name, center, axes, angle, startangle, endangle, color, thickness = para['img'], \
para['center'], \
para['axes'], \
para.get('angle', 0), \
para.get('startangle', 0), \
para.get('endangle', 360), \
para.get('color', [255, 255, 255]), \
para.get('thickness', 20)
img = cv2.imread(PREFIX + name)
cv2.ellipse(img, tuple(center), tuple(axes), angle, startangle, endangle, tuple(color), thickness)
cv2.imwrite(PREFIX + name, img)
@ -71,7 +79,8 @@ def process_ellipse(para):
def process_polylines(para):
name, point, isclosed, color = para['img'], para['point'], para['isclosed'], para['color']
name, point, isclosed, color = para['img'], para['point'], para.get('isclosed', True), \
para.get('color', [255, 255, 255])
img = cv2.imread(PREFIX + name)
pts = np.array(point, np.int32)
pts = pts.reshape((-1, 1, 2))
@ -81,7 +90,8 @@ def process_polylines(para):
def process_text(para):
name, text, org, fontsize, color = para['img'], para['text'], para['org'], para['fontsize'], para['color']
name, text, org, fontsize, color = para['img'], para['text'], para['org'], \
para.get('fontsize', 14), para.get('color', [255, 255, 255])
img = cv2.imread(PREFIX + name)
cv2.putText(img, text, org, fontFace=cv2.FONT_HERSHEY_SCRIPT_COMPLEX, fontScale=fontsize, color=tuple(color))
cv2.imwrite(PREFIX + name, img)

@ -9,7 +9,7 @@ urlpatterns = [
path('hsv/<str:color>', views.hsv_color_space),
path('rgb/<str:color>', views.rgb_color_space),
path('operation', views.basic_operation),
path('resize', views.resize),
path('resize_rotate_translation', views.resize),
path('rotate', views.rotate),
path('translation', views.translation),
path('flip', views.flip),

@ -25,7 +25,7 @@ def upload(request):
def basic_drawing(request):
if request.method == 'POST':
para = json.loads(request.body)
draw_type = para['type']
draw_type = para.get('type', 'bg')
if draw_type == 'bg':
return HttpResponse(process_bg())
else:
@ -80,9 +80,9 @@ def hsv_color_space(request, color):
elif color == 'v':
data = hsv[:, :, 2]
elif color == 'filter':
upper_bound = para.get('ub', [0, 0, 0])
lower_bound = para.get('lb', [200, 40, 100])
data = cv2.inRange(hsv, np.array(upper_bound), np.array(lower_bound))
upper_bound = para.get('ub', [200, 40, 100])
lower_bound = para.get('lb', [0, 0, 0])
data = cv2.inRange(hsv, np.array(lower_bound), np.array(upper_bound))
filename = color + '-' + image_name
cv2.imwrite(PREFIX + filename, data)
return HttpResponse(filename)
@ -95,8 +95,8 @@ def basic_operation(request):
para = json.loads(request.body)
operator = para['operator']
img = para['img']
has_color = para['color']
base = para['base']
has_color = para.get('color', 0)
base = para.get('base', 1)
if operator == 'and':
return HttpResponse(logic_and(img, has_color, base))
elif operator == 'or':
@ -197,7 +197,7 @@ def histogram(request):
if request.method == 'POST':
para = json.loads(request.body)
image = para['img']
color = para['color']
color = para.get('color', False)
histogram_name = get_image_name() + DEFAULT_FORMAT
if color:
img = cv2.imread(PREFIX + image)
@ -264,7 +264,7 @@ def edge_detection(request):
img = process_Canny(img)
# 这里由于返回格式的不同会在process_enhance之中直接返回不在往后执行
elif operator == 'Enhance':
process_enhance(img)
return process_enhance(img)
return HttpResponse(save_image(img))
return HttpResponse('Please use POST')
@ -275,7 +275,7 @@ def line_change_detection(request):
para = json.loads(request.body)
image = para['img']
img = cv2.imread(PREFIX + image)
use_p = para['use_p']
use_p = para.get('use_p', True)
img = cv2.GaussianBlur(img, (3, 3), 0)
edges = cv2.Canny(img, 50, 150, apertureSize=3)
if use_p:
@ -355,7 +355,8 @@ def morphology(request):
para = json.loads(request.body)
image = para['img']
size = para.get('size', 5)
img = cv2.imread(PREFIX + image, cv2.IMREAD_UNCHANGED)
img = cv2.imread(PREFIX + image, 0)
retval, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (size, size))
op = para['type']
if op == 'open':

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 648 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 833 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Loading…
Cancel
Save