久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 opencv copyTo() 函數(shù)?

How to use opencv copyTo() function?(如何使用 opencv copyTo() 函數(shù)?)
本文介紹了如何使用 opencv copyTo() 函數(shù)?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我已閱讀

請(qǐng)注意,在掩碼數(shù)組中填充了一個(gè)額外的維度,以便可以廣播.

I have read through the documentation for copyTo() but am still confused on how this function would be applied to the following code. This anwer states that we can use the copyTo function instead of 255-x. How would this function be applied in this case? I would appreciate a code snippet.

#   Compute the gradient map of the image
def doLap(image):

    # YOU SHOULD TUNE THESE VALUES TO SUIT YOUR NEEDS
    kernel_size = 5         # Size of the laplacian window
    blur_size = 5           # How big of a kernal to use for the gaussian blur
                            # Generally, keeping these two values the same or very close works well
                            # Also, odd numbers, please...

    blurred = cv2.GaussianBlur(image, (blur_size,blur_size), 0)
    return cv2.Laplacian(blurred, cv2.CV_64F, ksize=kernel_size)

#
#   This routine finds the points of best focus in all images and produces a merged result...
#
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

解決方案

Sorry that I kind of misled you there. Although it works nicely in C++, I cannot find the binding in Python. You can, however, use numpy.copyto function.

Here is a small demo that shows that both method (bitwise_not and copyto) produce identical result.

import cv2
import numpy as np

# Create two images
im1 = np.zeros((100, 100, 3), np.uint8)
im1[:] = (255, 0, 0)
im2 = np.zeros((100, 100, 3), np.uint8)
im2[:] = (0, 255, 0)

# Generate a random mask
ran = np.random.randint(0, 2, (100, 100), np.uint8)

# List of images and masks
images = [im1, im2]
mask = [ran, 1-ran]

not_output = np.zeros((100, 100, 3), np.uint8)
copy_output = np.zeros((100, 100, 3), np.uint8)

for i in range(0, len(images)):
    # Using the 'NOT' way
    not_output = cv2.bitwise_not(images[i], not_output, mask=mask[i])
    # Using the copyto way
    np.copyto(copy_output, images[i], where=mask[i][:, :, None].astype(bool))

cv2.imwrite('not.png', 255 - not_output)
cv2.imwrite('copy.png', copy_output)

Note that an extra dimension was padded to the mask array so that it can be broadcasted.

這篇關(guān)于如何使用 opencv copyTo() 函數(shù)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個(gè)矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測(cè)和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個(gè)矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測(cè)圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測(cè)圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美aaa级 | 国内精品久久久久久久影视简单 | 午夜欧美a级理论片915影院 | 亚洲国产精品一区二区久久 | 日韩精品视频在线观看一区二区三区 | 亚洲精品99 | 中文字幕一区二区三区乱码图片 | 日韩中文字幕第一页 | 男女午夜免费视频 | 日韩av看片 | 精品一区二区在线观看 | 日本高清不卡视频 | 色综合99 | 中文字幕 国产精品 | 日本在线黄色 | 国产精品久久久久久久久婷婷 | 久久精品这里 | 色偷偷噜噜噜亚洲男人 | 国产精品激情小视频 | 亚洲三区在线观看 | 亚洲精品久久久久中文字幕欢迎你 | 久久天天躁狠狠躁夜夜躁2014 | 国产精品视频久久 | 天天草草草 | 亚洲精品久久久久久宅男 | wwww.8888久久爱站网 | www.亚洲| 日韩有码在线播放 | 黄免费观看 | av中文在线 | 在线欧美视频 | 爱综合 | 天天干天天爱天天 | 精品国产一区二区三区性色 | 日韩视频一区 | 婷婷久久精品一区二区 | 久久久综合色 | 亚洲一区二区三区欧美 | 一区二区精品 | 亚州一区二区三区 | 最新中文字幕在线 |