How to use copy_image method in localstack

Best Python code snippet using localstack_python

image_filters.py

Source:image_filters.py Github

copy

Full Screen

1234import Cimpl5import typing67Image = typing.NewType('Image', str)8Color = typing.Tuple[int, int, int]91011def _adjust_component(number: int) -> int:12 """Returns an integer based off of the quadrant the given number lays in.1314 >>> _adjust_component(230)15 22316 >>> _adjust_component(50)17 3118 >>> _adjust_component(191)19 1592021 Written by Kaitlyn Johnson 10106457222 """2324 if 0 <= number <= 63:25 return 3126 if 64 <= number <= 127:27 return 9528 if 128 <= number <= 191:29 return 15930 if 192 <= number <= 255:31 return 223323334def _choose_color(color_name: str) -> Color:35 """36 Returns the proper color tuple given a color name3738 Colour options include: black, white, red, blue, yellow, lime, cyan,39 magenta, gray4041 >>> _choose_color('black')42 (0, 0, 0)43 >>> _choose_color('white')44 (255, 255, 255)45 >>> _choose_color('lime')46 (0, 255, 0)4748 Written By Nikita Yovchev (101140798)49 """5051 if color_name == "black":52 return 0, 0, 05354 elif color_name == "white":55 return 255, 255, 2555657 elif color_name == "red":58 return 255, 0, 05960 elif color_name == "blue":61 return 0, 0, 2556263 elif color_name == "yellow":64 return 255, 255, 06566 elif color_name == "lime":67 return 0, 255, 06869 elif color_name == "cyan":70 return 0, 255, 2557172 elif color_name == "magenta":73 return 255, 0, 2557475 elif color_name == "gray":76 return 128, 128, 128777879def _grayscale(image: Image) -> Image:80 """Return a grayscale copy of image.8182 >>> image = Cimpl.load_image(Cimpl.choose_file())83 >>> gray_image = _grayscale(image)84 >>> Cimpl.show(gray_image)8586 Written by D. Bailey (Carleton University)87 """88 new_image = Cimpl.copy(image)8990 for x, y, (r, g, b) in image:91 # Use the pixel's brightness as the value of RGB components for the92 # shade of gray. These means that the pixel's original colour and the93 # corresponding gray shade will have approximately the same brightness.9495 brightness = (r + g + b) // 39697 # or, brightness = (r + g + b) / 398 # create_color will convert an argument of type float to an int99100 gray = Cimpl.create_color(brightness, brightness, brightness)101 Cimpl.set_color(new_image, x, y, gray)102103 return new_image104105106def blue_filter(picture: Image) -> Image:107 """108 Returns a copy of the given picture that is blue monochromatic.109 The blue value of each pixel determines the brightness of the blue110 in the filtered copy.111112 >>> image = Cimpl.load_image(Cimpl.choose_file())113 >>> blue_image = blue_filter(image)114 >>> Cimpl.show(blue_image)115116 Written by Nikita Yovchev (101140798) using Cimpl library made at117 Carleton University, D. Bailey et al.118 """119120 copy_image = Cimpl.copy(picture)121122 for x, y, (r, g, b) in copy_image:123 new_blue = Cimpl.create_color(0, 0, b)124 Cimpl.set_color(copy_image, x, y, new_blue)125126 return copy_image127128129def green_filter(image: Image) -> Image:130 """131 Returns a copy of the image chosen in green.132133 >>> image = Cimpl.load_image(Cimpl.choose_file())134 >>> Green_Image = green_filter(image)135 >>> Cimpl.show(Green_Image)136137 Written by Andrea Chan 101107608 from simple_Cimple_filters138 at Carleton University by D. Bailey139 """140141 new_image = Cimpl.copy(image)142143 for x, y, (r, g, b) in image:144 new_green = Cimpl.create_color(0, g, 0)145 Cimpl.set_color(new_image, x, y, new_green)146147 return new_image148149150def red_filter(image: Image) -> Image:151 """152 Returns a new_copy of a picture chosen in red.153154 >>> image = Cimpl.load_image(Cimpl.choose_file())155 >>> red_image = red_filter(image)156 >>> Cimpl.show(red_image)157158 Written by Kaitlyn Johnson 101064572 from simple_Cimpl_filters159 at Carleton University by D. Bailey160 """161162 new_image = Cimpl.copy(image)163164 for x, y, (r, g, b) in image:165 new_red = Cimpl.create_color(r, 0, 0)166 Cimpl.set_color(new_image, x, y, new_red)167168 return new_image169170171def combine(red_image: Image, green_image: Image, blue_image: Image) -> Image:172 """173 This functions takes the red, green and blue images and returns another174 image with the red, blue and green monochromatics combined.175176 >>> red_image= Cimpl.load_image(Cimpl.choose_file())177 >>> blue_image = Cimpl.load_image(Cimpl.choose_file())178 >>> green_image = Cimpl.load_image(Cimpl.choose_file())179 >>> combine_image = combine(red_image, green_image, blue_image)180 >>> Cimpl.show(combine_image)181182 Name: Junaid Ahmed Askari183 Lab: L2-1184 Instructor: Donald Bailey185186 """187188 red = Cimpl.copy(red_image)189 green = Cimpl.copy(green_image)190 blue = Cimpl.copy(blue_image)191 color_images = Cimpl.copy(green_image)192193 for x, y, (r, g, b) in color_images:194 red_color = Cimpl.get_color(red, x, y)195 green_color = Cimpl.get_color(green, x, y)196 blue_color = Cimpl.get_color(blue, x, y)197198 new_image_color = Cimpl.create_color(red_color[0], green_color[1], blue_color[2])199 Cimpl.set_color(color_images, x, y, new_image_color)200201 return color_images202203204def two_toned_filter(picture: Image, colour_1: str, colour_2: str) -> Image:205 """Returns a copy of the given picture that recolored in the two206 tones given: the first tone will be for the darker pixels and the207 second tone for the lighter pixels.208209 Colour options include: black, white, red, blue, yellow, lime, cyan,210 magenta, gray211212 >>> image = Cimpl.load_image( Cimpl.choose_file())213 >>> two_toned_image = two_toned_filter(image, 'red', 'blue')214 >>> Cimpl.show(two_toned_image)215216 Written by Nikita Yovchev (101140798) using Cimpl library made at217 Carleton University, D. Bailey et al.218 """219220 copy_image = Cimpl.copy(picture)221222 for x, y, (r, g, b) in copy_image:223 if ((r + g + b) // 3) <= 127:224 new_color = _choose_color(colour_1)225 Cimpl.set_color(copy_image, x, y, Cimpl.create_color(new_color[0], new_color[1], new_color[2]))226227 else:228 new_color = _choose_color(colour_2)229 Cimpl.set_color(copy_image, x, y, Cimpl.create_color(new_color[0], new_color[1], new_color[2]))230231 return copy_image232233234def three_toned_filter(picture: Image, colour_1: str, colour_2: str, colour_3: str) -> Image:235 """Returns a copy of the given picture that recolored in the three tones236 given: the first tone will be for the darkest pixels, the second tone for237 the medium brightness pixels, and the third for the lighter pixels.238239 Colour options include: black, white, red, blue, yellow, lime, cyan, magenta, gray240241 >>> image = Cimpl.load_image(Cimpl.choose_file())242 >>> three_toned_image = three_toned_filter(image, 'magenta', 'lime', 'cyan')243 >>> Cimpl.show(three_toned_image)244245 Written by Nikita Yovchev (101140798) using Cimpl library made at246 Carleton University, D. Bailey et al.247 """248249 copy_image = Cimpl.copy(picture)250251 for x, y, (r, g, b) in copy_image:252 if ((r + g + b) // 3) <= 84:253 new_color = _choose_color(colour_1)254 Cimpl.set_color(copy_image, x, y, Cimpl.create_color(new_color[0], new_color[1], new_color[2]))255256 elif 85 <= ((r + g + b) // 3) <= 170:257 new_color = _choose_color(colour_2)258 Cimpl.set_color(copy_image, x, y, Cimpl.create_color(new_color[0], new_color[1], new_color[2]))259260 else:261 new_color = _choose_color(colour_3)262 Cimpl.set_color(copy_image, x, y, Cimpl.create_color(new_color[0], new_color[1], new_color[2]))263 264 return copy_image265266267def extreme_contrast(image: Image) -> Image:268 """Returns a copy of an image in which the copy is an extreme contrasted269 version of the original image.270271 >>> image = Cimpl.load_image(Cimpl.choose_file())272 >>> contrast = extreme_contrast(image)273 >>> Cimpl.show(contrast)274275 Written by Andrea Chan 101107608276 """277278 contrast_image = Cimpl.copy(image)279 for x, y, (r, g, b) in contrast_image:280 r, g, b = Cimpl.get_color(contrast_image, x, y)281 if 0 <= r <= 127:282 contrast_red = 0283 elif 128 <= r <= 255:284 contrast_red = 255285 if 0 <= g <= 127:286 contrast_green = 0287 elif 128 <= g <= 255:288 contrast_green = 255289 if 0 <= b <= 127:290 contrast_blue = 0291 elif 128 <= b <= 255:292 contrast_blue = 255293294 new_image_color = Cimpl.create_color(contrast_red, contrast_green, contrast_blue)295 Cimpl.set_color(contrast_image, x, y, new_image_color)296297 return contrast_image298299300def sepia(new_image: Image) -> Image:301 """302 The function takes the gray image, created by the grayscale filter provided by the303 prof on CULEARN, and adds a sepia tint on it, which is a hint of yellow.304305 >>> image = Cimpl.load_image(Cimpl.choose_file())306 >>> sepia_image = sepia(image)307 >>> Cimpl.show(sepia_image)308309 written by: Junaid Ahmed Askari310 Student number: 101111448311 """312313 sepia_image = Cimpl.copy(_grayscale(new_image))314315 for x, y, (r, g, b) in new_image:316 darkness = Cimpl.get_color(sepia_image, x, y)317318 if sum(darkness) <= 189:319 new_color = Cimpl.create_color(darkness[0] * 1.1, darkness[1], darkness[2] * 0.9)320 Cimpl.set_color(sepia_image, x, y, new_color)321322 elif 189 <= sum(darkness) <= 573:323 new_color = Cimpl.create_color(darkness[0] * 1.15, darkness[1], darkness[2] * 0.85)324 Cimpl.set_color(sepia_image, x, y, new_color)325326 elif sum(darkness) >= 573:327 new_color = Cimpl.create_color(darkness[0] * 1.08, darkness[1], darkness[2] * 0.93)328 Cimpl.set_color(sepia_image, x, y, new_color)329330 return sepia_image331332333def posterizing(image: Image) -> Image:334 """Returns a copy of the Image that is posterized (simplified colors).335336 >>> image = Cimpl.load_image(Cimpl.choose_file())337 >>> post_image = posterizing(image)338 >>> Cimpl.show(post_image)339340 Written by Kaitlyn Johnson 101064572 from simple_Cimpl_filters at Carleton341 University by D. Bailey342 """343344 new_image = Cimpl.copy(image)345346 for x, y, (r, g, b) in image:347 adjusted_r = _adjust_component(r)348 adjusted_g = _adjust_component(g)349 adjusted_b = _adjust_component(b)350351 new_posterizing = Cimpl.create_color(adjusted_r, adjusted_g, adjusted_b)352 Cimpl.set_color(new_image, x, y, new_posterizing)353354 return new_image355356357def detect_edges(picture: Image, threshold: int) -> Image:358 """Returns a black and white copy of the image provided with a specific359 contrast threshold that is composed only of the edges (looks like a sketch).360361 >>> image = Cimpl.load_image(Cimpl.choose_file())362 >>> edge_image = detect_edges(image, 12)363 >>> Cimpl.show(edge_image)364365 Written by Nikita Yovchev (101140798) using Cimpl library made at366 Carleton University, D. Bailey et al.367 """368369 white = Cimpl.create_color(255, 255, 255)370 black = Cimpl.create_color(0, 0, 0)371 copy_image = Cimpl.copy(picture)372373 for x, y, (r, g, b) in copy_image:374 if y < (Cimpl.get_height(copy_image) - 1):375 pixel_colour_bot = Cimpl.get_color(copy_image, x, y + 1)376377 average_top = (r + b + g) // 3378 average_bot = (pixel_colour_bot[0] + pixel_colour_bot[1] + pixel_colour_bot[2]) // 3379380 if abs(average_bot - average_top) <= threshold:381 Cimpl.set_color(copy_image, x, y, white)382383 else:384 Cimpl.set_color(copy_image, x, y, black)385386 return copy_image387388389def detect_edges_better(picture: Image, thresh: int) -> Image:390 """Returns a new and improved edge-only copy of the picture with a given391 threshold. This edged image is better because it compares the contrast392 between more pixels than the previous edge function.393394 >>> image = Cimpl.load_image(Cimpl.choose_file())395 >>> edge_image = detect_edges_better(image, 12)396 >>> Cimpl.show(edge_image)397398 Written by Kaitlyn Johnson (101064572) and Nikita Yovchev (101140798)399 using Cimpl library made at Carleton University, D. Bailey et al.400 """401402 white = Cimpl.create_color(255, 255, 255)403 black = Cimpl.create_color(0, 0, 0)404 copy_image = Cimpl.copy(picture)405406 for x, y, (r, g, b) in copy_image:407 if y == (Cimpl.get_height(copy_image) - 1):408 if x != (Cimpl.get_width(copy_image) - 1):409 pixel_color_right = Cimpl.get_color(copy_image, x + 1, y)410 average_right = (pixel_color_right[0] + pixel_color_right[1] + pixel_color_right[2]) // 3411 average_current = (r + g + b) // 3412413 if abs(average_right - average_current) < thresh:414 Cimpl.set_color(copy_image, x, y, white)415416 else:417 Cimpl.set_color(copy_image, x, y, black)418419 elif x == (Cimpl.get_width(copy_image) - 1):420 if y != (Cimpl.get_height(copy_image) - 1):421 pixel_color_bot = Cimpl.get_color(copy_image, x, y + 1)422 average_bot = (pixel_color_bot[0] + pixel_color_bot[1] + pixel_color_bot[2]) // 3423 average_current = (r + g + b) // 3424425 if abs(average_bot - average_current) < thresh:426 Cimpl.set_color(copy_image, x, y, white)427428 else:429 Cimpl.set_color(copy_image, x, y, black)430431 elif x < (Cimpl.get_width(copy_image) - 1) and y < (Cimpl.get_height(copy_image) - 1):432 pixel_color_bot = Cimpl.get_color(copy_image, x, y + 1)433 pixel_color_right = Cimpl.get_color(copy_image, x + 1, y)434435 average_bot = (pixel_color_bot[0] + pixel_color_bot[1] + pixel_color_bot[2]) // 3436 average_right = (pixel_color_right[0] + pixel_color_right[1] + pixel_color_right[2]) // 3437 average_current = (r + g + b) // 3438439 if abs(average_bot - average_current) and abs(average_right - average_current) < thresh:440 Cimpl.set_color(copy_image, x, y, white)441442 else:443 Cimpl.set_color(copy_image, x, y, black)444445 return copy_image446447448def flip_vertical(image: Image) -> Image:449 """450 Returns a copy of the Image provided that is flipped along a vertical line in the center.451452 >>> choose_image = Cimpl.load_image(Cimpl.choose_file())453 >>> vertical_image = flip_vertical(choose_image)454 >>> Cimpl.show(vertical_image)455456 Written by: Junaid Ahmed Askari457 Student Number: 101111448458 """459460 vertically_flipped = Cimpl.copy(image)461 height_of_image = Cimpl.get_height(vertically_flipped)462 half_width = (Cimpl.get_width(vertically_flipped)) // 2463464 for y in range(0, height_of_image):465 for x in range(0, half_width):466 original_colour = Cimpl.get_color(vertically_flipped, x, y)467 opposite_colour = Cimpl.get_color(vertically_flipped, -x, y)468469 Cimpl.set_color(vertically_flipped, x, y, opposite_colour)470 Cimpl.set_color(vertically_flipped, -x, y, original_colour)471472 return vertically_flipped473474475def flip_horizontal(image: Image) -> Image:476 """Returns a copy of the image selected flipped along the middle of the horizon line477478 >>> image = Cimpl.load_image(Cimpl.choose_file())479 >>> horizontal_image = flip_horizontal(image)480 >>> Cimpl.show(horizontal_image)481482 Written by Andrea Chan 101107608 using Cimpl Library483 """484485 horizontal_image = Cimpl.copy(image)486 length = Cimpl.get_height(horizontal_image)487 width = Cimpl.get_width(horizontal_image)488489 for x in range(0, width):490 for y in range(0, length // 2):491 top_colour = Cimpl.get_color(horizontal_image, x, y)492 bottom_colour = Cimpl.get_color(horizontal_image, x, -y)493494 Cimpl.set_color(horizontal_image, x, y, bottom_colour)495 Cimpl.set_color(horizontal_image, x, -y, top_colour)496 ...

Full Screen

Full Screen

image_manipulator.py

Source:image_manipulator.py Github

copy

Full Screen

1#!/usr/bin/env python22""" Manipulates images to be used in Video Recorder"""3import numpy as np4# from theia_msgs.msg import ZoneAlarm5#pylint: disable=import-error6import cv27def correct_image_size(image, target_width, target_height):8 """function correct the size of images"""9 if type(image) is not np.ndarray:10 print("Image is not of type {}".format(np.ndarray))11 return image12 copy_image = image.copy()13 if (copy_image.shape()[0], copy_image.shape()[1]) != (target_height, target_width):14 if check_aspect_ratios_equal(copy_image.shape, (target_width, target_height)):15 if copy_image.shape()[0] != target_height:16 copy_image = resize_image_mantain_aspect_ratio(copy_image, height=target_height)17 elif copy_image.shape()[1] != target_width:18 copy_image = resize_image_mantain_aspect_ratio(copy_image, width=target_width)19 else:20 if copy_image.shape()[1] > target_width:21 copy_image = crop_width(copy_image, target_width)22 elif copy_image.shape()[1] < target_width:23 copy_image = pad_width(copy_image, target_width)24 if copy_image.shape()[0] > target_height:25 copy_image = crop_height(copy_image, target_height)26 elif copy_image.shape()[0]< target_height:27 copy_image = pad_height(copy_image, target_height)28 return copy_image29def resize_image_mantain_aspect_ratio(image, width=None, height=None):30 """resize images of similar aspect ratios"""31 # initialize the dimensions of the image to be resized and grab the image size32 dim = None33 (h, w) = image.shape[:2]34 if width is None and height is None:35 return image36 # check to see if the width is None37 if width is None:38 # calculate the ratio of the height and construct the dimensions39 r = height / float(h)40 dim = (int(w * r), height)41 else:42 # calculate the ratio of the width and construct the dimensions43 r = width / float(w)44 dim = (width, int(h * r))45 #pylint: disable=c-extension-no-member46 resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)47 return resized48def check_aspect_ratios_equal(shape1, shape2):49 """check the aspect ratio of an image"""50 return float("{0:.2f}".format(float(shape1[1])/float(shape1[0]))) == float("{0:.2f}".format(float(shape2[1])/float(shape2[0])))51def border_image(image, border_depth, color = [0, 0 , 0]):52 """ adds a border which changes color based on the level of violation"""53 color = color54 inside_border_depth = int(border_depth * .75)55 outside_border_depth = int(border_depth * .25)56 copy_image = image.copy()57 copy_image = cv2.copyMakeBorder(copy_image, inside_border_depth, inside_border_depth, inside_border_depth, inside_border_depth,58 cv2.BORDER_CONSTANT, value=color)59 copy_image = cv2.copyMakeBorder(copy_image, outside_border_depth, outside_border_depth, outside_border_depth, outside_border_depth,60 cv2.BORDER_CONSTANT, value=[0, 0, 0])61 return copy_image62def stitch_images(images, logo, no_image):63 """Stitches together the frames from all cameras"""64 # Take Orb images and make a tiled image65 # Make a huge grid video using all images from all orbs66 # ___________________67 # | | | |68 # | 1 | 2 | 3 |69 # |_____|_____|_____|70 # | | | |71 # | 4 | LOGO| 5 |72 # |_____|_____|_____|73 # | | | |74 # | 6 | 7 | 8 |75 # |_____|_____|_____|76 if len(images) < 8:77 #pylint: disable=unused-variable78 for i in range(len(images), 9):79 images.append(no_image)80 stitched_image = np.vstack((np.hstack((images[0], images[1], images[2])),81 np.hstack((images[3], logo, images[4])),82 np.hstack((images[5], images[6], images[7]))))83 return stitched_image84def add_text_to_image(image, text):85 '''Write the date and time on the image'''86 image = image.copy()87 org = (10, image.shape[0] - 10)88 #pylint: disable=c-extension-no-member89 font_face = cv2.FONT_HERSHEY_SIMPLEX90 font_scale = 191 color = (75, 25, 230) #RED92 thickness = 293 line_type = 2 #cv2.LINE_AA94 #pylint: disable=c-extension-no-member95 image = cv2.putText(image, text, org, font_face, font_scale, color, thickness, line_type)96 return image97def pad_width(image, target_width):98 '''pads the width of the image'''99 left = -(-(target_width - np.size(image, 1))//2) #ceiling division100 right = left101 if (target_width - np.size(image, 1))%2 != 0:102 right -= 1103 return np.pad(image, ((0, 0), (left, right), (0, 0)), 'constant', constant_values=(0, 0))104def pad_height(image, target_height):105 '''pads the height of the image'''106 top = -(-(target_height - np.size(image, 0))//2) #ceiling division107 bottom = top108 if (target_height - np.size(image, 0))%2 != 0:109 bottom -= 1110 return np.pad(image, ((top, bottom), (0, 0), (0, 0)), 'constant', constant_values=(0, 0))111def crop_width(image, target_width):112 '''crops the width of the image'''113 x = np.size(image, 1)114 start = x//2-(target_width//2)115 return image[0:np.size(image, 0), start:start+target_width]116def crop_height(image, target_height):117 '''crops the height of the image'''118 y = np.size(image, 0)119 start = y//2-(target_height//2)...

Full Screen

Full Screen

detecting_text.py

Source:detecting_text.py Github

copy

Full Screen

1import cv22import numpy as np3def get_image():4 """5 Hàm này dùng để đọc ảnh và thay đổi kích thước hiển thị của6 :return:7 """8 img = cv2.imread('6.png')9 copy_image = np.copy(img)10 copy_image = cv2.resize(copy_image, (0, 0), fx=0.3, fy=0.3)11 # print(copy_image.shape)12 return copy_image13def processing_image(copy_image):14 """15 hàm này dùng để xử lý ảnh đầu vào, bao gồm đọc ảnh, thay đổi kích thước, phát hiện biên, giãn những dòng text trong16 :return: ảnh gốc và ảnh có những dòng text bị giãn ra17 """18 copy_img = cv2.cvtColor(copy_image, cv2.COLOR_BGR2GRAY)19 edge_img= cv2.Canny(copy_img,100, 200)20 kernel = np.ones((1,1), dtype=np.uint8)21 erosion = cv2.erode(edge_img, kernel, iterations=1)22 kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))23 dilation = cv2.dilate(erosion, kernel, iterations=2)24 # cv2.imshow('image', dilation)25 return dilation26def finding_contours(dilation):27 """28 tìm contours của ảnh29 :param dilation: ảnh mà có những dong text đã giãn ra30 :return: contours31 """32 contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)33 return contours34def draw_tictoe(copy_image):35 """36 hàm này dùng để vẽ ngẫu nhiên 20 dấu tic toe37 :param copy_image:38 :return: ảnh đã vẽ tic toe39 """40 positions = [(np.random.randint(0, 600), np.random.randint(0, 850)) for i in range(20)]41 for pos in positions:42 cv2.drawMarker(copy_image, pos, (0, 0, 255), markerType=cv2.MARKER_TILTED_CROSS, markerSize=15,43 thickness=3, line_type=8)44 cv2.imshow('image', copy_image)45 return positions46def detecting_text(copy_image, contours):47 """48 Hàm này dùng để phát hiện những đoạn text và vẽ boudingbox cho nó49 :param dilation: ảnh mà bên trong có những dòng text bị giãn50 :param copy_image: ảnh được copy từ ảnh gốc51 :return:52 """53 for cnt in contours:54 area = cv2.contourArea(cnt)55 if area < 5000 and area > 100:56 x,y,w,h = cv2.boundingRect(cnt)57 x2, y2 = x+w, y+h58 cv2.rectangle(copy_image, (x,y), (x2, y2), (0,255,0), 3)59 cv2.imshow('image', copy_image)60def detecting_box(copy_image, contours):61 """62 Hàm này dùng để phát hiện những ô trả lời lớn và vẽ contours cho nó63 :param dilation: ảnh mà bên trong có những dòng text bị giãn64 :param copy_image: ảnh được copy từ ảnh gốc65 :return:66 """67 for cnt in contours:68 area = cv2.contourArea(cnt)69 if area > 15000:70 cv2.drawContours(copy_image, cnt, -1, (0, 0, 255), 5)71 cv2.imshow('image', copy_image)72def detect_tictoe(copy_image, contours, positions):73 """74 hàm này dùng để vẽ contours lên các ô trả lời lớn nếu các ô này chứa dấu tictioe75 :param copy_image: ảnh đầu vào76 :param contours: các contour77 :param positions: vị trí của các dấu tictoe78 :return:79 """80 for cnt in contours:81 area = cv2.contourArea(cnt)82 if area > 15000:83 retval = [cv2.pointPolygonTest(cnt, pos, measureDist= False) for pos in positions]84 for each in retval:85 if each > 0:86 cv2.drawContours(copy_image, cnt, -1, (0, 0, 255), 2)87 cv2.imshow('image', copy_image)88if __name__ == '__main__':89 copy_image = get_image()90 dilation = processing_image(copy_image)91 contours = finding_contours(dilation)92 # detecting_text(dilation, copy_image)93 # box = detecting_box(copy_image, contours)94 positions = draw_tictoe(copy_image)95 detect_tictoe(copy_image, contours, positions)96 cv2.waitKey()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful