當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.add方法代碼示例

本文整理匯總了Python中cv2.add方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.add方法的具體用法?Python cv2.add怎麽用?Python cv2.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cv2的用法示例。


在下文中一共展示了cv2.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: maximizeContrast

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def maximizeContrast(imgGrayscale):

    height, width = imgGrayscale.shape

    imgTopHat = np.zeros((height, width, 1), np.uint8)
    imgBlackHat = np.zeros((height, width, 1), np.uint8)

    structuringElement = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))

    imgTopHat = cv2.morphologyEx(imgGrayscale, cv2.MORPH_TOPHAT, structuringElement)
    imgBlackHat = cv2.morphologyEx(imgGrayscale, cv2.MORPH_BLACKHAT, structuringElement)

    imgGrayscalePlusTopHat = cv2.add(imgGrayscale, imgTopHat)
    imgGrayscalePlusTopHatMinusBlackHat = cv2.subtract(imgGrayscalePlusTopHat, imgBlackHat)

    return imgGrayscalePlusTopHatMinusBlackHat
# end function 
開發者ID:muchlisinadi,項目名稱:ALPR-Indonesia,代碼行數:19,代碼來源:Preprocess.py

示例2: random_hue_saturation_value

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def random_hue_saturation_value(image,
                                hue_shift_limit=(-180, 180),
                                sat_shift_limit=(-255, 255),
                                val_shift_limit=(-255, 255)):

    image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    h, s, v = cv2.split(image)
    hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
    h = cv2.add(h, hue_shift)
    sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
    s = cv2.add(s, sat_shift)
    val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
    v = cv2.add(v, val_shift)
    image = cv2.merge((h, s, v))
    image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)

    return image 
開發者ID:asanakoy,項目名稱:kaggle_carvana_segmentation,代碼行數:19,代碼來源:train.py

示例3: detect_shirt

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def detect_shirt(self):
        
        
        #self.dst=cv2.inRange(self.norm_rgb,np.array([self.lb,self.lg,self.lr],np.uint8),np.array([self.b,self.g,self.r],np.uint8))
        self.dst=cv2.inRange(self.norm_rgb,np.array([20,20,20],np.uint8),np.array([255,110,80],np.uint8))
        cv2.threshold(self.dst,0,255,cv2.THRESH_OTSU+cv2.THRESH_BINARY)
        fg=cv2.erode(self.dst,None,iterations=2)
        #cv2.imshow("fore",fg)  
        bg=cv2.dilate(self.dst,None,iterations=3)
        _,bg=cv2.threshold(bg, 1,128,1)
        #cv2.imshow("back",bg)
        
        mark=cv2.add(fg,bg)
        mark32=np.int32(mark)
        cv2.watershed(self.norm_rgb,mark32)
        self.m=cv2.convertScaleAbs(mark32)
        _,self.m=cv2.threshold(self.m,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
        #cv2.imshow("final_tshirt",self.m)
        
        cntr,h=cv2.findContours(self.m,cv2.cv.CV_RETR_EXTERNAL,cv2.cv.CV_CHAIN_APPROX_SIMPLE)
               
        return self.m,cntr 
開發者ID:akash0x53,項目名稱:virtual-dressing-room,代碼行數:24,代碼來源:Tshirt.py

示例4: randomHueSaturationValue

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def randomHueSaturationValue(image, hue_shift_limit=(-180, 180),
                             sat_shift_limit=(-255, 255),
                             val_shift_limit=(-255, 255), u=0.5):
    if np.random.random() < u:
        image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
        h, s, v = cv2.split(image)
        hue_shift = np.random.uniform(hue_shift_limit[0], hue_shift_limit[1])
        h = cv2.add(h, hue_shift)
        sat_shift = np.random.uniform(sat_shift_limit[0], sat_shift_limit[1])
        s = cv2.add(s, sat_shift)
        val_shift = np.random.uniform(val_shift_limit[0], val_shift_limit[1])
        v = cv2.add(v, val_shift)
        image = cv2.merge((h, s, v))
        image = cv2.cvtColor(image, cv2.COLOR_HSV2BGR)

    return image 
開發者ID:petrosgk,項目名稱:Kaggle-Carvana-Image-Masking-Challenge,代碼行數:18,代碼來源:train.py

示例5: render

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def render(img, res):
    res *= 255
    res = res.astype(np.uint8)

    res = cv2.cvtColor(res, cv2.COLOR_GRAY2BGR)  # to white color
    res[:, :, 0] = 0  # remove blue channel
    res[:, :, 2] = 0  # remove red channel

    res = cv2.resize(res, (WIDTH, HEIGHT), interpolation=cv2.INTER_LINEAR)  # resize 15x8 to 1280x720
    org = cv2.resize(img, (WIDTH, HEIGHT))
    added = cv2.add(org, res)  # combine input, output

    cv2.imshow('result', added)
    cv2.waitKey(0)
    # if cv2.waitKey(1) & 0xFF == ord('q'):
    #     print('User Interrupted')
    #     exit(1) 
開發者ID:YoongiKim,項目名稱:Walk-Assistant,代碼行數:19,代碼來源:client.py

示例6: visualize

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def visualize(img):
    global grid

    grid = np.round(grid)

    h, w, c = img.shape
    box = np.zeros((h, w), dtype=np.uint8)
    for i in range(len(grid)):
        for j in range(len(grid[i])):
            box[i*KERNEL : (i+1)*KERNEL, j*KERNEL : (j+1)*KERNEL] = grid[i][j] * 255

    box = cv2.cvtColor(box, cv2.COLOR_GRAY2BGR)
    box[:,:,0]=0
    box[:,:,2]=0

    visual = cv2.add(img, box)

    for i in range(0, HEIGHT, KERNEL):  # 가로선
        cv2.line(visual, (0, i), (WIDTH, i), color=(255,255,255))
    for i in range(0, WIDTH, KERNEL):  # 세로선
        cv2.line(visual, (i, 0), (i, HEIGHT), color=(255,255,255))

    return visual 
開發者ID:YoongiKim,項目名稱:Walk-Assistant,代碼行數:25,代碼來源:annotation.py

示例7: subtract_bgnd

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def subtract_bgnd(self, image):
        # new method using bitwise not
        def _remove_func(_img, _func, _bg):
            #the reason to use opencv2 instead of numpy is to avoid buffer overflow
            #https://stackoverflow.com/questions/45817037/opencv-image-subtraction-vs-numpy-subtraction/45817868
            new_img = np.zeros_like(_img); #maybe can do this in place
            if image.ndim == 2:
                _func(_img, _bg, new_img)
            else:
                for ii, this_frame in enumerate(_img):
                    _func(this_frame, _bg, new_img[ii])
            return new_img
        
        bg = self.bgnd.astype(np.uint8)
        if self.is_light_background:
            notbg = ~bg
            ss = _remove_func(image, cv2.add, notbg)
        else: # fluorescence
            ss = _remove_func(image, cv2.subtract, bg)
            
        ss = np.clip( ss ,1,255);
        
        return ss 
開發者ID:ver228,項目名稱:tierpsy-tracker,代碼行數:25,代碼來源:BackgroundSubtractor.py

示例8: _draw_on_top

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [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_ 
開發者ID:jerry-git,項目名稱:thug-memes,代碼行數:19,代碼來源:thug.py

示例9: get_init_process_img

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def get_init_process_img(roi_img):
    """
    對圖片進行初始化處理,包括,梯度化,高斯模糊,二值化,腐蝕,膨脹和邊緣檢測
    :param roi_img: ndarray
    :return: ndarray
    """
    h = cv2.Sobel(roi_img, cv2.CV_32F, 0, 1, -1)
    v = cv2.Sobel(roi_img, cv2.CV_32F, 1, 0, -1)
    img = cv2.add(h, v)
    img = cv2.convertScaleAbs(img)
    img = cv2.GaussianBlur(img, (3, 3), 0)
    ret, img = cv2.threshold(img, 120, 255, cv2.THRESH_BINARY)
    kernel = np.ones((1, 1), np.uint8)
    img = cv2.erode(img, kernel, iterations=1)
    img = cv2.dilate(img, kernel, iterations=2)
    img = cv2.erode(img, kernel, iterations=1)
    img = cv2.dilate(img, kernel, iterations=2)
    img = auto_canny(img)
    return img 
開發者ID:inuyasha2012,項目名稱:answer-sheet-scan,代碼行數:21,代碼來源:utils.py

示例10: _shift_hsv_non_uint8

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def _shift_hsv_non_uint8(img, hue_shift, sat_shift, val_shift):
    dtype = img.dtype
    img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    hue, sat, val = cv2.split(img)

    if hue_shift != 0:
        hue = cv2.add(hue, hue_shift)
        hue = np.where(hue < 0, hue + 180, hue)
        hue = np.where(hue > 180, hue - 180, hue)
        hue = hue.astype(dtype)

    if sat_shift != 0:
        sat = clip(cv2.add(sat, sat_shift), dtype, 255 if dtype == np.uint8 else 1.0)

    if val_shift != 0:
        val = clip(cv2.add(val, val_shift), dtype, 255 if dtype == np.uint8 else 1.0)

    img = cv2.merge((hue, sat, val)).astype(dtype)
    img = cv2.cvtColor(img, cv2.COLOR_HSV2RGB)
    return img 
開發者ID:albumentations-team,項目名稱:albumentations,代碼行數:22,代碼來源:functional.py

示例11: _execute

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [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) 
開發者ID:dreamnettech,項目名稱:dreampower,代碼行數:24,代碼來源:watermark.py

示例12: getthresholdedimg

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def getthresholdedimg(hsv):
    yellow = cv2.inRange(hsv, np.array((20, 100, 100)), np.array((30, 255, 255)))
    blue = cv2.inRange(hsv, np.array((100, 100, 100)), np.array((120, 255, 255)))
    both = cv2.add(yellow, blue)
    return both 
開發者ID:arturaugusto,項目名稱:display_ocr,代碼行數:7,代碼來源:OCR.py

示例13: _split_channel_images

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def _split_channel_images(self):
        blue, green, red = cv2.split(self._image)

        split_channel_images = [
            red,
            green,
            blue,
            cv2.add(red, green),
            cv2.add(red, blue),
            cv2.add(green, blue)
        ]

        return split_channel_images 
開發者ID:nemanja-m,項目名稱:gaps,代碼行數:15,代碼來源:size_detector.py

示例14: read

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def read(self, dst=None):
        w, h = self.frame_size

        if self.bg is None:
            buf = np.zeros((h, w, 3), np.uint8)
        else:
            buf = self.bg.copy()

        self.render(buf)

        if self.noise > 0.0:
            noise = np.zeros((h, w, 3), np.int8)
            cv2.randn(noise, np.zeros(3), np.ones(3)*255*self.noise)
            buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)
        return True, buf 
開發者ID:makelove,項目名稱:OpenCV-Python-Tutorial,代碼行數:17,代碼來源:video.py

示例15: read

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import add [as 別名]
def read(self, dst=None):
        w, h = self.frame_size

        if self.bg is None:
            buf = np.zeros((h, w, 3), np.uint8)
        else:
            buf = self.bg.copy()

        self.render(buf)

        if self.noise > 0.0:
            noise = np.zeros((h, w, 3), np.int8)
            cv2.randn(noise, np.zeros(3), np.ones(3) * 255 * self.noise)
            buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)
        return True, buf 
開發者ID:mengli,項目名稱:MachineLearning,代碼行數:17,代碼來源:video.py


注:本文中的cv2.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。