本文整理汇总了Python中cv2.bitwise_not方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.bitwise_not方法的具体用法?Python cv2.bitwise_not怎么用?Python cv2.bitwise_not使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.bitwise_not方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: standard_test
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def standard_test(self):
for fnum in range(self.start_fnum, self.stop_fnum):
frame = util.get_frame(self.capture, fnum)
frame = frame[280:, :]
frame_HSV = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(frame_HSV, (self.low_H, self.low_S, self.low_V),
(self.high_H, self.high_S, self.high_V))
res = cv2.bitwise_and(frame, frame, mask=mask)
res_inv = cv2.bitwise_and(frame, frame, mask=cv2.bitwise_not(mask))
cv2.imshow(self.window_name, mask)
cv2.imshow('Video Capture AND', res)
cv2.imshow('Video Capture INV', res_inv)
if cv2.waitKey(30) & 0xFF == ord('q'):
break
# A number of methods corresponding to the various trackbars available.
示例2: fillhole
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def fillhole(input_image):
'''
input gray binary image get the filled image by floodfill method
Note: only holes surrounded in the connected regions will be filled.
:param input_image:
:return:
'''
im_flood_fill = input_image.copy()
h, w = input_image.shape[:2]
mask = np.zeros((h + 2, w + 2), np.uint8)
im_flood_fill = im_flood_fill.astype("uint8")
cv.floodFill(im_flood_fill, mask, (0, 0), 255)
im_flood_fill_inv = cv.bitwise_not(im_flood_fill)
img_out = input_image | im_flood_fill_inv
return img_out
示例3: pre_process_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def pre_process_image(img, skip_dilate=False):
"""Uses a blurring function, adaptive thresholding and dilation to expose the main features of an image."""
# Gaussian blur with a kernal size (height, width) of 9.
# Note that kernal sizes must be positive and odd and the kernel must be square.
proc = cv2.GaussianBlur(img.copy(), (9, 9), 0)
# Adaptive threshold using 11 nearest neighbour pixels
proc = cv2.adaptiveThreshold(proc, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
# Invert colours, so gridlines have non-zero pixel values.
# Necessary to dilate the image, otherwise will look like erosion instead.
proc = cv2.bitwise_not(proc, proc)
if not skip_dilate:
# Dilate the image to increase the size of the grid lines.
kernel = np.array([[0., 1., 0.], [1., 1., 1.], [0., 1., 0.]],np.uint8)
proc = cv2.dilate(proc, kernel)
return proc
示例4: paste_patch
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
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)
示例5: Load_DigitImages
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def Load_DigitImages(digitImgPath, imgPxls):
if not rfi.PathExists(digitImgPath): return # os.path.isdir(digitImgPath): return
if imgPxls<=0:return
imgW = int(np.sqrt(imgPxls))
digitImgs = []
for i in range(10):
fn = digitImgPath + "{}.jpg".format(i)
image = np.array(Image.open(fn))
# 將 cv2 的 BGR 轉成 image的 RGB--------------------------
#image = ru.CvBGR_To_RGB(image)
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#gray = cv2.bitwise_not(gray) #反相
gray = cv2.resize(gray, (imgW, imgW))
# if Debug:
# plt.title('result={}, Label={}'.format(i,i))
# plt.imshow(gray, cmap='gray')
# plt.show()
#gray = cv2.resize(gray, (1,imgPxls) )/255.0 圖形錯誤
gray = gray.reshape((imgPxls,1) )/255.0
if Debug:
rf.Plot_Digit([gray.transpose(),0], i,i)
digitImgs.append(gray)
return digitImgs
示例6: flood_fill_single
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def flood_fill_single(im, seed_point):
"""Perform a single flood fill operation.
# Arguments
image: an image. the image should consist of white background, black lines and black fills.
the white area is unfilled area, and the black area is filled area.
seed_point: seed point for trapped-ball fill, a tuple (integer, integer).
# Returns
an image after filling.
"""
pass1 = np.full(im.shape, 255, np.uint8)
im_inv = cv2.bitwise_not(im)
mask1 = cv2.copyMakeBorder(im_inv, 1, 1, 1, 1, cv2.BORDER_CONSTANT, 0)
_, pass1, _, _ = cv2.floodFill(pass1, mask1, seed_point, 0, 0, 0, 4)
return pass1
示例7: test_find_largest_contours
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def test_find_largest_contours(self):
"""Test if largest contours is found. """
# setup
test_path = utils.get_full_path('docs/material_for_testing/back_ground_removed_frame.jpg')
test_image = cv2.imread(test_path)
# Because image loaded from local, and not received from web-cam, a flip is needed.
test_image = cv2.flip(test_image, 1)
test_image = cv2.bitwise_not(test_image)
max_area_contour = ImageTestTool.get_max_area_contour(test_image)
expected_area = ImageTestTool.get_contour_area(max_area_contour)
# Create detector
flags_handler = FlagsHandler()
detector = Detector(flags_handler)
# run
detector.input_frame_for_feature_extraction = test_image
result_area = cv2.contourArea(detector.max_area_contour)
assert result_area == expected_area
示例8: focus_stack
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def focus_stack(unimages):
images = align_images(unimages)
print "Computing the laplacian of the blurred images"
laps = []
for i in range(len(images)):
print "Lap {}".format(i)
laps.append(doLap(cv2.cvtColor(images[i],cv2.COLOR_BGR2GRAY)))
laps = np.asarray(laps)
print "Shape of array of laplacians = {}".format(laps.shape)
output = np.zeros(shape=images[0].shape, dtype=images[0].dtype)
abs_laps = np.absolute(laps)
maxima = abs_laps.max(axis=0)
bool_mask = abs_laps == maxima
mask = bool_mask.astype(np.uint8)
for i in range(0,len(images)):
output = cv2.bitwise_not(images[i],output, mask=mask[i])
return 255-output
示例9: getSignature
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def getSignature(img):
imgSize = np.shape(img)
gImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Adaptive Thresholding requires the blocksize to be odd and bigger than 1
blockSize = 1 / 8 * imgSize[0] / 2 * 2 + 1
if blockSize <= 1:
blockSize = imgSize[0] / 2 * 2 + 1
const = 10
mask = cv2.adaptiveThreshold(gImg, maxValue = 255, adaptiveMethod = cv2.ADAPTIVE_THRESH_MEAN_C, thresholdType = cv2.THRESH_BINARY, blockSize = blockSize, C = const)
rmask = cv2.bitwise_not(mask)
return (cv2.bitwise_and(img, img, mask=rmask), rmask)
# First Prompt
示例10: add_background
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
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
示例11: _draw_on_top
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def _draw_on_top(self, img, x, y, sub_img, sub_name=''):
h, w, _ = sub_img.shape
mask = sub_img[:, :, 3]
mask_inv = cv2.bitwise_not(mask)
sub_img_ = sub_img[:, :, :3]
background = img[y:y + h, x:x + w]
try:
background = cv2.bitwise_and(background, background, mask=mask_inv)
except cv2.error as e:
raise ThugError(
'Can not draw {}, please try with smaller {}.'.format(
sub_name, sub_name))
foreground = cv2.bitwise_and(sub_img_, sub_img_, mask=mask)
sum_ = cv2.add(background, foreground)
img[y:y + h, x:x + w] = sum_
示例12: invert
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def invert(gray_img):
"""Inverts grayscale images.
Inputs:
gray_img = Grayscale image data
Returns:
img_inv = inverted image
:param gray_img: numpy.ndarray
:return img_inv: numpy.ndarray
"""
params.device += 1
img_inv = cv2.bitwise_not(gray_img)
if params.debug == 'print':
print_image(img_inv, os.path.join(params.debug_outdir, str(params.device) + '_invert.png'))
elif params.debug == 'plot':
plot_image(img_inv, cmap='gray')
return img_inv
示例13: image_preprocessor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def image_preprocessor(image):
image = im.equalize_light(image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
black_level = im.back_in_black(image)
image = im.gauss_filter(image, (3,3))
image = im.light(image, bright=-30, contrast=-30)
if not black_level:
image = cv2.bitwise_not(image)
kernel = np.ones((5,5), np.uint8)
mask = cv2.erode(image, kernel, iterations=1)
mask = cv2.dilate(mask, kernel, iterations=1)
image = np.subtract(image, mask)
return im.threshold(image, clip=5)
示例14: _execute
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def _execute(self, *args):
"""
Create a watermark image.
:param agrs: <[RGB}> image to watermark
:return: <RGB> watermarked image
"""
# Add alpha channel if missing
if args[0].shape[2] < 4:
img = np.dstack([args[0], np.ones((512, 512), dtype="uint8") * 255])
f1 = np.asarray([0, 0, 0, 250]) # red color filter
f2 = np.asarray([255, 255, 255, 255])
mask = cv2.bitwise_not(cv2.inRange(self.__watermark, f1, f2))
mask_inv = cv2.bitwise_not(mask)
res1 = cv2.bitwise_and(img, img, mask=mask)
res2 = cv2.bitwise_and(self.__watermark, self.__watermark, mask=mask_inv)
res = cv2.add(res1, res2)
alpha = 0.6
return cv2.addWeighted(res, alpha, img, 1 - alpha, 0)
示例15: tensor2image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import bitwise_not [as 别名]
def tensor2image(image, img_path =None,img_shape=None):
tmp_img = np.squeeze(image_normalization(image))
tmp_img = np.uint8(cv.resize(tmp_img,(img_shape[1],img_shape[0])))
tmp_img = cv.bitwise_not(tmp_img)
cv.imwrite(img_path,tmp_img)
print("Prediction saved in:",img_path)