Python cv2.bitwise_or() Examples
The following are 30
code examples of cv2.bitwise_or().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: thresholding.py From smashscan with MIT License | 12 votes |
def contour_filter(self, frame): _, contours, _ = cv2.findContours(frame, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) new_frame = np.zeros(frame.shape, np.uint8) for i, contour in enumerate(contours): c_area = cv2.contourArea(contour) if self.contour_min_area <= c_area <= self.contour_max_area: mask = np.zeros(frame.shape, np.uint8) cv2.drawContours(mask, contours, i, 255, cv2.FILLED) mask = cv2.bitwise_and(frame, mask) new_frame = cv2.bitwise_or(new_frame, mask) frame = new_frame if self.contour_disp_flag: frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) cv2.drawContours(frame, contours, -1, (255, 0, 0), 1) return frame # A number of methods corresponding to the various trackbars available.
Example #2
Source File: main.py From Traffic-Sign-Detection with MIT License | 8 votes |
def remove_other_color(img): frame = cv2.GaussianBlur(img, (3,3), 0) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) # define range of blue color in HSV lower_blue = np.array([100,128,0]) upper_blue = np.array([215,255,255]) # Threshold the HSV image to get only blue colors mask_blue = cv2.inRange(hsv, lower_blue, upper_blue) lower_white = np.array([0,0,128], dtype=np.uint8) upper_white = np.array([255,255,255], dtype=np.uint8) # Threshold the HSV image to get only blue colors mask_white = cv2.inRange(hsv, lower_white, upper_white) lower_black = np.array([0,0,0], dtype=np.uint8) upper_black = np.array([170,150,50], dtype=np.uint8) mask_black = cv2.inRange(hsv, lower_black, upper_black) mask_1 = cv2.bitwise_or(mask_blue, mask_white) mask = cv2.bitwise_or(mask_1, mask_black) # Bitwise-AND mask and original image #res = cv2.bitwise_and(frame,frame, mask= mask) return mask
Example #3
Source File: line_detect_2.py From crop_row_detection with GNU General Public License v3.0 | 7 votes |
def skeletonize(image_in): '''Inputs and grayscale image and outputs a binary skeleton image''' size = np.size(image_in) skel = np.zeros(image_in.shape, np.uint8) ret, image_edit = cv2.threshold(image_in, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3)) done = False while not done: eroded = cv2.erode(image_edit, element) temp = cv2.dilate(eroded, element) temp = cv2.subtract(image_edit, temp) skel = cv2.bitwise_or(skel, temp) image_edit = eroded.copy() zeros = size - cv2.countNonZero(image_edit) if zeros == size: done = True return skel
Example #4
Source File: functions.py From malayalam-character-recognition with MIT License | 7 votes |
def skeletize(img): size = np.size(img) skel = np.zeros(img.shape, np.uint8) element = cv2.getStructuringElement(cv2.MORPH_CROSS, (3, 3)) done = False while not done: eroded = cv2.erode(img, element) temp = cv2.dilate(eroded, element) temp = cv2.subtract(img, temp) skel = cv2.bitwise_or(skel, temp) img = eroded.copy() zeroes = size - cv2.countNonZero(img) if zeroes == size: done = True return skel
Example #5
Source File: rule_based.py From PythonPilot with Apache License 2.0 | 6 votes |
def binarize(self, src): """Image binarization. Args: src (int): Input image BGR. numpy.ndarray, (256, 512, 3), 0~255 Returns: dst (int): Output image. numpy.ndarray, (256, 512), 0~1 """ # resize if src.shape[0] != self.__height or src.shape[1] != self.__width: src = cv2.resize(src, (self.__width, self.__height), interpolation=cv2.INTER_LINEAR) # image thresholding image_binary_canny = self.__apply_canny(src) image_binary_mthreshold = self.__apply_multi_threshold(src) image_binary_all = cv2.bitwise_or(image_binary_canny, image_binary_mthreshold) # mask top and bottom dst = self.__mask_image(image_binary_all) return dst
Example #6
Source File: extract_color.py From python-image-processing with MIT License | 6 votes |
def extract_color( src, h_th_low, h_th_up, s_th, v_th ): hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsv) if h_th_low > h_th_up: ret, h_dst_1 = cv2.threshold(h, h_th_low, 255, cv2.THRESH_BINARY) ret, h_dst_2 = cv2.threshold(h, h_th_up, 255, cv2.THRESH_BINARY_INV) dst = cv2.bitwise_or(h_dst_1, h_dst_2) else: ret, dst = cv2.threshold(h, h_th_low, 255, cv2.THRESH_TOZERO) ret, dst = cv2.threshold(dst, h_th_up, 255, cv2.THRESH_TOZERO_INV) ret, dst = cv2.threshold(dst, 0, 255, cv2.THRESH_BINARY) ret, s_dst = cv2.threshold(s, s_th, 255, cv2.THRESH_BINARY) ret, v_dst = cv2.threshold(v, v_th, 255, cv2.THRESH_BINARY) dst = cv2.bitwise_and(dst, s_dst) dst = cv2.bitwise_and(dst, v_dst) return dst
Example #7
Source File: getFoodContourMorph.py From tierpsy-tracker with MIT License | 6 votes |
def skeletonize(img): """ OpenCV function to return a skeletonized version of img, a Mat object""" # hat tip to http://felix.abecassis.me/2011/09/opencv-morphological-skeleton/ img = img.copy() # don't clobber original skel = img.copy() skel[:,:] = 0 kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (3,3)) while True: eroded = cv2.morphologyEx(img, cv2.MORPH_ERODE, kernel) temp = cv2.morphologyEx(eroded, cv2.MORPH_DILATE, kernel) temp = cv2.subtract(img, temp) skel = cv2.bitwise_or(skel, temp) img[:,:] = eroded[:,:] if cv2.countNonZero(img) == 0: break return skel
Example #8
Source File: ImageProcessing.py From OctoPNP with GNU Affero General Public License v3.0 | 6 votes |
def _maskBackground(self, img, mask_corners = True): h,w,c = np.shape(img) blur_img=cv2.blur(img, (5,5)) hsv = cv2.cvtColor(blur_img, cv2.COLOR_BGR2HSV) lower_color = np.array([22,28,26]) upper_color = np.array([103,255,255]) # create binary mask by finding background color range mask = cv2.inRange(hsv, self.lower_mask_color, self.upper_mask_color) # remove the corners from mask since they are prone to illumination problems if(mask_corners): circle_mask = np.zeros((h, w), np.uint8) circle_mask[:, :] = 255 cv2.circle(circle_mask,(w/2, h/2), min(w/2, h/2), 0, -1) mask = cv2.bitwise_or(mask,circle_mask) # invert mask to get white objects on black background #inverse_mask = 255 - mask if self._interactive: cv2.imshow("binary mask", mask) if self._interactive: cv2.waitKey(0) return mask
Example #9
Source File: logical_or.py From plantcv with MIT License | 6 votes |
def logical_or(bin_img1, bin_img2): """Join two images using the bitwise OR operator. Inputs: bin_img1 = Binary image data to be compared to bin_img2 bin_img2 = Binary image data to be compared to bin_img1 Returns: merged = joined binary image :param bin_img1: numpy.ndarray :param bin_img2: numpy.ndarray :return merged: numpy.ndarray """ params.device += 1 merged = cv2.bitwise_or(bin_img1, bin_img2) if params.debug == 'print': print_image(merged, os.path.join(params.debug_outdir, str(params.device) + '_or_joined.png')) elif params.debug == 'plot': plot_image(merged, cmap='gray') return merged
Example #10
Source File: utils_img.py From pyslam with GNU General Public License v3.0 | 6 votes |
def add_background(img, img_box, img_background=None): if img_background is None: # create random image img_background = draw_random_img(img.shape) else: # check if we have to resize img_background if img_background.shape != img.shape: #print('resizing img background') (h, w) = img.shape[:2] img_background = cv2.resize(img_background,(w,h)) # check if we have to convert to gray image if img.ndim == 2: img_background = cv2.cvtColor(img_background,cv2.COLOR_RGB2GRAY) #print('img.shape:',img.shape,', img_background.shape:',img_background.shape) mask = mask_from_polygon(img.shape,img_box) inverse_mask = cv2.bitwise_not(mask) img_background = cv2.bitwise_or(img_background, img_background, mask=inverse_mask) # combine foreground+background final = cv2.bitwise_or(img, img_background) return final
Example #11
Source File: visualizer.py From open_model_zoo with Apache License 2.0 | 6 votes |
def overlay_masks(self, image, masks, classes, ids=None): colors = self.compute_colors_for_labels(classes).tolist() segments_image = image.copy() aggregated_mask = np.zeros(image.shape[:2], dtype=np.uint8) aggregated_colored_mask = np.zeros(image.shape, dtype=np.uint8) black = np.zeros(3, dtype=np.uint8) for i, (mask, color) in enumerate(zip(masks, colors)): color_idx = i if ids is None else ids[i] mask_color = self.instance_color_palette[color_idx % len(self.instance_color_palette)].tolist() cv2.bitwise_or(aggregated_mask, mask, dst=aggregated_mask) cv2.bitwise_or(aggregated_colored_mask, np.asarray(mask_color, dtype=np.uint8), dst=aggregated_colored_mask, mask=mask) # Fill the area occupied by all instances with a colored instances mask image. cv2.bitwise_and(segments_image, black, dst=segments_image, mask=aggregated_mask) cv2.bitwise_or(segments_image, aggregated_colored_mask, dst=segments_image, mask=aggregated_mask) # Blend original image with the one, where instances are colored. # As a result instances masks become transparent. cv2.addWeighted(image, 0.5, segments_image, 0.5, 0, dst=image) return image
Example #12
Source File: ui_sketch.py From iSketchNFill with GNU General Public License v3.0 | 6 votes |
def paste_patch(self,pos,w,paste_img): pos_x = int(pos.x()/self.scale) pos_y = int(pos.y()/self.scale) w = int(w) paste_img = cv2.resize(paste_img,(self.img_size,self.img_size)) mask = np.full((self.img_size, self.img_size), 0 ,dtype = np.uint8) mask = cv2.rectangle(mask,(pos_x,pos_y),( pos_x + w , pos_y + w ),(255,255,255),thickness=-1) img = self.img foreground_img = cv2.bitwise_or(paste_img,paste_img,mask=mask) back_mask = cv2.bitwise_not(mask) background_img = cv2.bitwise_or(img, img, mask = back_mask) self.img = cv2.bitwise_or(foreground_img,background_img)
Example #13
Source File: 1b-est-gyro-rates.py From ImageAnalysis with MIT License | 5 votes |
def overlay(new_frame, base, motion_mask=None): newtmp = cv2.cvtColor(new_frame, cv2.COLOR_BGR2GRAY) ret, newmask = cv2.threshold(newtmp, 0, 255, cv2.THRESH_BINARY_INV) blendsize = (3,3) kernel = np.ones(blendsize,'uint8') mask_dilate = cv2.dilate(newmask, kernel) #cv2.imshow('mask_dilate', mask_dilate) ret, mask_final = cv2.threshold(mask_dilate, 254, 255, cv2.THRESH_BINARY) if args.draw_masks: cv2.imshow('mask_final', mask_final) mask_inv = 255 - mask_final if motion_mask != None: motion_inv = 255 - motion_mask mask_inv = cv2.bitwise_and(mask_inv, motion_mask) cv2.imshow('mask_inv1', mask_inv) mask_final = cv2.bitwise_or(mask_final, motion_inv) cv2.imshow('mask_final1', mask_final) if args.draw_masks: cv2.imshow('mask_inv', mask_inv) mask_final_norm = mask_final / 255.0 mask_inv_norm = mask_inv / 255.0 base[:,:,0] = base[:,:,0] * mask_final_norm base[:,:,1] = base[:,:,1] * mask_final_norm base[:,:,2] = base[:,:,2] * mask_final_norm #cv2.imshow('base', base) new_frame[:,:,0] = new_frame[:,:,0] * mask_inv_norm new_frame[:,:,1] = new_frame[:,:,1] * mask_inv_norm new_frame[:,:,2] = new_frame[:,:,2] * mask_inv_norm accum = cv2.add(base, new_frame) #cv2.imshow('accum', accum) return accum
Example #14
Source File: 1a-est-gyro-rates.py From ImageAnalysis with MIT License | 5 votes |
def overlay(new_frame, base, motion_mask=None): newtmp = cv2.cvtColor(new_frame, cv2.COLOR_BGR2GRAY) ret, newmask = cv2.threshold(newtmp, 0, 255, cv2.THRESH_BINARY_INV) blendsize = (3,3) kernel = np.ones(blendsize,'uint8') mask_dilate = cv2.dilate(newmask, kernel) #cv2.imshow('mask_dilate', mask_dilate) ret, mask_final = cv2.threshold(mask_dilate, 254, 255, cv2.THRESH_BINARY) if args.draw_masks: cv2.imshow('mask_final', mask_final) mask_inv = 255 - mask_final if motion_mask != None: motion_inv = 255 - motion_mask mask_inv = cv2.bitwise_and(mask_inv, motion_mask) cv2.imshow('mask_inv1', mask_inv) mask_final = cv2.bitwise_or(mask_final, motion_inv) cv2.imshow('mask_final1', mask_final) if args.draw_masks: cv2.imshow('mask_inv', mask_inv) mask_final_norm = mask_final / 255.0 mask_inv_norm = mask_inv / 255.0 base[:,:,0] = base[:,:,0] * mask_final_norm base[:,:,1] = base[:,:,1] * mask_final_norm base[:,:,2] = base[:,:,2] * mask_final_norm #cv2.imshow('base', base) new_frame[:,:,0] = new_frame[:,:,0] * mask_inv_norm new_frame[:,:,1] = new_frame[:,:,1] * mask_inv_norm new_frame[:,:,2] = new_frame[:,:,2] * mask_inv_norm accum = cv2.add(base, new_frame) #cv2.imshow('accum', accum) return accum
Example #15
Source File: 1a-est-gyro-rates.py From ImageAnalysis with MIT License | 5 votes |
def overlay(new_frame, base, motion_mask=None): newtmp = cv2.cvtColor(new_frame, cv2.COLOR_BGR2GRAY) ret, newmask = cv2.threshold(newtmp, 0, 255, cv2.THRESH_BINARY_INV) blendsize = (3,3) kernel = np.ones(blendsize,'uint8') mask_dilate = cv2.dilate(newmask, kernel) #cv2.imshow('mask_dilate', mask_dilate) ret, mask_final = cv2.threshold(mask_dilate, 254, 255, cv2.THRESH_BINARY) if args.draw_masks: cv2.imshow('mask_final', mask_final) mask_inv = 255 - mask_final if motion_mask != None: motion_inv = 255 - motion_mask mask_inv = cv2.bitwise_and(mask_inv, motion_mask) cv2.imshow('mask_inv1', mask_inv) mask_final = cv2.bitwise_or(mask_final, motion_inv) cv2.imshow('mask_final1', mask_final) if args.draw_masks: cv2.imshow('mask_inv', mask_inv) mask_final_norm = mask_final / 255.0 mask_inv_norm = mask_inv / 255.0 base[:,:,0] = base[:,:,0] * mask_final_norm base[:,:,1] = base[:,:,1] * mask_final_norm base[:,:,2] = base[:,:,2] * mask_final_norm #cv2.imshow('base', base) new_frame[:,:,0] = new_frame[:,:,0] * mask_inv_norm new_frame[:,:,1] = new_frame[:,:,1] * mask_inv_norm new_frame[:,:,2] = new_frame[:,:,2] * mask_inv_norm accum = cv2.add(base, new_frame) #cv2.imshow('accum', accum) return accum
Example #16
Source File: utils.py From alpr_utils with GNU General Public License v3.0 | 5 votes |
def apply_plate(image, points, plate): image = image.astype("uint8").asnumpy() plate = plate.astype("uint8").asnumpy() points = np.array(points).reshape((2, 4)) points = points * np.array([[image.shape[1]], [image.shape[0]]]) pts = rect_matrix(0, 0, plate.shape[1], plate.shape[0]) t_pts = points_matrix(points) m = transform_matrix(pts, t_pts) mask = np.ones_like(plate, dtype=np.uint8) mask = cv2.warpPerspective(mask, m, (image.shape[1], image.shape[0])) mask = (mask == 0).astype(np.uint8) * 255 plate = cv2.warpPerspective(plate, m, (image.shape[1], image.shape[0])) return mx.nd.array(cv2.bitwise_or(cv2.bitwise_and(image, mask), plate))
Example #17
Source File: toolbox_opencv.py From remi with Apache License 2.0 | 5 votes |
def process(self): if not self.img1 is None: if not self.img2 is None: self.set_image_data(cv2.bitwise_or(self.img1, self.img1, mask=self.img2))
Example #18
Source File: remove_noise.py From image_text_reader with MIT License | 5 votes |
def remove_noise_and_smooth(file_name): logging.info('Removing noise and smoothening image') img = cv2.imread(file_name, 0) filtered = cv2.adaptiveThreshold(img.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 41, 3) kernel = np.ones((1, 1), np.uint8) opening = cv2.morphologyEx(filtered, cv2.MORPH_OPEN, kernel) closing = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel) img = image_smoothening(img) or_image = cv2.bitwise_or(img, closing) return or_image
Example #19
Source File: genplate_plate.py From basicOCR with GNU General Public License v3.0 | 5 votes |
def generate(self, text): if len(text) == 9: fg = self.draw(text.decode(encoding="utf-8")) fg = cv2.bitwise_not(fg) com = cv2.bitwise_or(fg, self.bg) com = rot(com, r(60) - 30, com.shape, 30) com = rotRandrom(com, 10, (com.shape[1], com.shape[0])) # com = AddSmudginess(com,self.smu) com = tfactor(com) com = random_envirment(com, self.noplates_path) com = AddGauss(com, 1 + r(4)) com = addNoise(com) return com
Example #20
Source File: genplate_plate.py From basicOCR with GNU General Public License v3.0 | 5 votes |
def random_envirment(img, data_set): index = r(len(data_set)) env = cv2.imread(data_set[index]) env = cv2.resize(env, (img.shape[1], img.shape[0])) bak = (img == 0) bak = bak.astype(np.uint8) * 255 inv = cv2.bitwise_and(bak, env) img = cv2.bitwise_or(inv, img) return img
Example #21
Source File: __init__.py From magicwand with MIT License | 5 votes |
def _mouse_callback(self, event, x, y, flags, *userdata): if event != cv.EVENT_LBUTTONDOWN: return modifier = flags & (ALT_KEY + SHIFT_KEY) self._flood_mask[:] = 0 cv.floodFill( self.img, self._flood_mask, (x, y), 0, self.tolerance, self.tolerance, self._flood_fill_flags, ) flood_mask = self._flood_mask[1:-1, 1:-1].copy() if modifier == (ALT_KEY + SHIFT_KEY): self.mask = cv.bitwise_and(self.mask, flood_mask) elif modifier == SHIFT_KEY: self.mask = cv.bitwise_or(self.mask, flood_mask) elif modifier == ALT_KEY: self.mask = cv.bitwise_and(self.mask, cv.bitwise_not(flood_mask)) else: self.mask = flood_mask self._update()
Example #22
Source File: visualizer.py From open_model_zoo with Apache License 2.0 | 5 votes |
def overlay_masks(self, image, masks, ids=None): segments_image = image.copy() aggregated_mask = np.zeros(image.shape[:2], dtype=np.uint8) aggregated_colored_mask = np.zeros(image.shape, dtype=np.uint8) black = np.zeros(3, dtype=np.uint8) all_contours = [] for i, mask in enumerate(masks): color_idx = i if ids is None else ids[i] mask_color = self.instance_color_palette[color_idx % len(self.instance_color_palette)].tolist() contours = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[-2] if contours: all_contours.append(contours[0]) cv2.bitwise_or(aggregated_mask, mask, dst=aggregated_mask) cv2.bitwise_or(aggregated_colored_mask, np.asarray(mask_color, dtype=np.uint8), dst=aggregated_colored_mask, mask=mask) # Fill the area occupied by all instances with a colored instances mask image. cv2.bitwise_and(segments_image, black, dst=segments_image, mask=aggregated_mask) cv2.bitwise_or(segments_image, aggregated_colored_mask, dst=segments_image, mask=aggregated_mask) # Blend original image with the one, where instances are colored. # As a result instances masks become transparent. cv2.addWeighted(image, 0.5, segments_image, 0.5, 0, dst=image) cv2.drawContours(image, all_contours, -1, (0, 0, 0)) return image
Example #23
Source File: handling_image.py From PythonPilot with Apache License 2.0 | 5 votes |
def binary_mask_overlay(src, binary_mask): """Image overlaying. Args: src (int): Input image BGR. numpy.ndarray, (720, 1280, 3), 0~255 binary_mask (int): Input image. numpy.ndarray, (720, 1280), 0~1 Returns: dst (int): Output image BGR. numpy.ndarray, (720, 1280, 3), 0~255 """ # resize if src.shape[0] != binary_mask.shape[0] or src.shape[1] != binary_mask.shape[1]: binary_mask = cv2.resize(binary_mask, (src.shape[1], src.shape[0]), interpolation=cv2.INTER_LINEAR) # prepare white and red image image_all_mid_white = np.dstack((binary_mask*255, binary_mask*255, binary_mask*255)) image_all_mid_red = np.dstack((binary_mask*0, binary_mask*0, binary_mask*255)) # combine src and thresholded image not_mask = cv2.bitwise_not(image_all_mid_white) src_masked = cv2.bitwise_and(src, not_mask) dst = cv2.bitwise_or(src_masked, image_all_mid_red) return dst
Example #24
Source File: extract.py From dreampower with GNU General Public License v3.0 | 5 votes |
def get_correct_filter_color(image, part_name): """Get the correct color filter.""" def get_simple_mask(image, l1, l2): f1 = np.asarray(l1) # aur color filter f2 = np.asarray(l2) color_mask = cv2.inRange(image, f1, f2) return color_mask if part_name == "tit": # Use combined color filter f1 = np.asarray([0, 0, 0]) # tit color filter f2 = np.asarray([10, 10, 10]) f3 = np.asarray([0, 0, 250]) # aur color filter f4 = np.asarray([0, 0, 255]) color_mask1 = cv2.inRange(image, f1, f2) color_mask2 = cv2.inRange(image, f3, f4) color_mask = cv2.bitwise_or(color_mask1, color_mask2) # combine elif part_name == "aur": color_mask = get_simple_mask(image, [0, 0, 250], [0, 0, 255]) elif part_name == "vag": color_mask = get_simple_mask(image, [250, 0, 0], [255, 0, 0]) elif part_name == "belly": color_mask = get_simple_mask(image, [250, 0, 250], [255, 0, 255]) return color_mask
Example #25
Source File: convenience.py From imutils with MIT License | 5 votes |
def skeletonize(image, size, structuring=cv2.MORPH_RECT): # determine the area (i.e. total number of pixels in the image), # initialize the output skeletonized image, and construct the # morphological structuring element area = image.shape[0] * image.shape[1] skeleton = np.zeros(image.shape, dtype="uint8") elem = cv2.getStructuringElement(structuring, size) # keep looping until the erosions remove all pixels from the # image while True: # erode and dilate the image using the structuring element eroded = cv2.erode(image, elem) temp = cv2.dilate(eroded, elem) # subtract the temporary image from the original, eroded # image, then take the bitwise 'or' between the skeleton # and the temporary image temp = cv2.subtract(image, temp) skeleton = cv2.bitwise_or(skeleton, temp) image = eroded.copy() # if there are no more 'white' pixels in the image, then # break from the loop if area == area - cv2.countNonZero(image): break # return the skeletonized image return skeleton
Example #26
Source File: handsegment.py From sign-language-gesture-recognition with MIT License | 5 votes |
def handsegment(frame): lower, upper = boundaries[0] lower = np.array(lower, dtype="uint8") upper = np.array(upper, dtype="uint8") mask1 = cv2.inRange(frame, lower, upper) lower, upper = boundaries[1] lower = np.array(lower, dtype="uint8") upper = np.array(upper, dtype="uint8") mask2 = cv2.inRange(frame, lower, upper) # for i,(lower, upper) in enumerate(boundaries): # # create NumPy arrays from the boundaries # lower = np.array(lower, dtype = "uint8") # upper = np.array(upper, dtype = "uint8") # # find the colors within the specified boundaries and apply # # the mask # if(i==0): # print "Harish" # mask1 = cv2.inRange(frame, lower, upper) # else: # print "Aadi" # mask2 = cv2.inRange(frame, lower, upper) mask = cv2.bitwise_or(mask1, mask2) output = cv2.bitwise_and(frame, frame, mask=mask) # show the images # cv2.imshow("images", mask) # cv2.imshow("images", output) return output
Example #27
Source File: masterForgery.py From signature_extractor with MIT License | 5 votes |
def displayImageToScreen(img, mask): imgSize = np.shape(img) bg = np.zeros((imgSize[0], imgSize[1], 3), np.uint8) bg[:, :] = (255, 255, 255) # Add a white background to the signature rmask = cv2.bitwise_not(mask) bgROI = cv2.bitwise_and(bg, bg, mask = rmask) sigROI = cv2.bitwise_and(signature, signature, mask = mask) roi = cv2.bitwise_or(bgROI, sigROI) cv2.imshow('Signature', roi) cv2.waitKey(0)
Example #28
Source File: LogicalOperation.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 5 votes |
def main(): basePath = "../data/" imageFileOne = basePath + "4.1.04.tiff" imageFileTwo = basePath + "4.1.05.tiff" imageOne = cv2.imread(imageFileOne, 1) imageTwo = cv2.imread(imageFileTwo, 1) imageOneRGB = cv2.cvtColor(imageOne, cv2.COLOR_BGR2RGB) imageTwoRGB = cv2.cvtColor(imageTwo, cv2.COLOR_BGR2RGB) negativeImage = cv2.bitwise_not(imageOneRGB) andImage = cv2.bitwise_and(imageOneRGB, imageTwoRGB) orImage = cv2.bitwise_or(imageOneRGB, imageTwoRGB) xorImage = cv2.bitwise_xor(imageOneRGB, imageTwoRGB) imageNames = [imageOneRGB, imageTwoRGB, negativeImage, andImage, orImage, xorImage] imageTitles = ["Image One", "Image Two", "Negative", "AND", "OR", "XOR"] for i in range(6): plt.subplot(2, 3, i + 1) plt.imshow(imageNames[i]) plt.title(imageTitles[i]) plt.xticks([]) plt.yticks([]) plt.show()
Example #29
Source File: genplate.py From deep_learning with MIT License | 5 votes |
def generate(self, text): if len(text) == 7: fg = self.draw(text) fg = cv2.bitwise_not(fg) com = cv2.bitwise_or(fg, self.bg) com = rot(com, r(60) - 30, com.shape, 30) com = rotRandrom(com, 10, (com.shape[1], com.shape[0])) #com = AddSmudginess(com,self.smu) com = tfactor(com) com = random_envirment(com, self.noplates_path) com = AddGauss(com, 1 + r(4)) com = addNoise(com) return com
Example #30
Source File: genplate.py From deep_learning with MIT License | 5 votes |
def random_envirment(img, data_set): index = r(len(data_set)) env = cv2.imread(data_set[index]) env = cv2.resize(env, (img.shape[1], img.shape[0])) bak = (img == 0) bak = bak.astype(np.uint8) * 255 inv = cv2.bitwise_and(bak, env) img = cv2.bitwise_or(inv, img) return img