国产无码免费,人妻口爆,国产V在线,99中文精品7,国产成人无码AA精品一,制度丝袜诱惑av,久久99免费麻辣视频,蜜臀久久99精品久久久久久酒店
        訂閱
        糾錯
        加入自媒體

        如何使用Python OpenCV混合圖像?

        2021-06-15 08:59
        磐創AI
        關注

        在這篇文章中,我們將提供一些使用OpenCV的示例。

        在OpenCV中混合圖像我們將提供一個逐步的示例,說明如何使用Python OpenCV混合圖像。下面我們展示了目標圖像和濾鏡圖像。

        目標圖像

        濾鏡圖像

        import cv2

        # Two images
        img1 = cv2.imread('target.jpg')
        img2 = cv2.imread('filter.png')

        # OpenCV expects to get BGR images, so we will convert from BGR to RGB

        img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)
        img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2RGB)

        # Resize the Images. In order to blend them, the two images
        # must be of the same shape

        img1 =cv2.resize(img1,(620,350))
        img2 =cv2.resize(img2,(620,350))


        # Now, we can blend them, we need to define the weight (alpha) of the target image
        # as well as the weight of the filter image
        # in our case we choose 80% target and 20% filter
        blended = cv2.addWeighted(src1=img1,alpha=0.8,src2=img2,beta=0.2,gamma=0)

        # finally we can save the image. Now we need to convert it from RGB to BGR

        cv2.imwrite('Blending.png',cv2.cvtColor(blended, cv2.COLOR_RGB2BGR))

        在OpenCV中處理圖像我們將展示如何使用Python中的OpenCV應用圖像處理。

        如何模糊影像import cv2
        import numpy as np
        import matplotlib.pyplot as plt
        %matplotlib inline

        img = cv2.imread('panda.jpeg')
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        blurred_img = cv2.blur(img,ksize=(20,20))
        cv2.imwrite("blurredpanda.jpg", blurred_img)

        如何申請Sobel Operator你可以在Wikipedia上查看Sobel Operator:https://en.wikipedia.org/wiki/Sobel_operator也可以開始嘗試一些過濾器。讓我們應用水平和垂直Sobel。img = cv2.imread('panda.jpeg',0)
        sobelx = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=5)
        sobely = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=5)

        cv2.imwrite("sobelx_panda.jpg", sobelx)
        cv2.imwrite("sobely_panda.jpg", sobely)

        如何對圖像應用閾值我們還可以對圖像進行二值化。img = cv2.imread('panda.jpeg',0)
        ret,th1 = cv2.threshold(img,100,255,cv2.THRESH_BINARY)
        fig = plt.figure(figsize=(12,10))
        plt.imshow(th1,cmap='gray')

        OpenCV中的人臉檢測我們將討論如何使用OpenCV應用人臉檢測。我們通過一個實際的可重現的示例來直截了當。邏輯如下:我們從URL(或從硬盤)獲取圖像。我們將其轉換為numpy array,然后轉換為灰度。然后通過應用適當的**CascadeClassifier,**我們獲得了人臉的邊界框。最后,使用PIllow(甚至是OpenCV),我們可以在初始圖像上繪制框。import cv2 as cv
        import numpy as np
        import PIL
        from PIL import Image
        import requests
        from io import BytesIO
        from PIL import ImageDraw


        # I have commented out the cat and eye cascade. Notice that the xml files are in the opencv folder that you have downloaded and installed
        # so it is good a idea to write the whole path
        face_cascade = cv.CascadeClassifier('C:\opencv\build\etc\haarcascades\haarcascade_frontalface_default.xml')
        #cat_cascade = cv.CascadeClassifier('C:\opencv\build\etc\haarcascades\haarcascade_frontalcatface.xml')
        #eye_cascade = cv.CascadeClassifier('C:\opencv\build\etc\haarcascades\haarcascade_eye.xml')


        URL = "https://images.unsplash.com/photo-1525267219888-bb077b8792cc?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
        response = requests.get(URL)
        img = Image.open(BytesIO(response.content))
        img_initial = img.copy()

        # convert it to np array
        img = np.asarray(img)

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

        faces = face_cascade.detectMultiScale(gray)
        # And lets just print those faces out to the screen
        #print(faces)

        drawing=ImageDraw.Draw(img_initial)

        # For each item in faces, lets surround it with a red box
        for x,y,w,h in faces:
           # That might be new syntax for you! Recall that faces is a list of rectangles in (x,y,w,h)
           # format, that is, a list of lists. Instead of having to do an iteration and then manually
           # pull out each item, we can use tuple unpacking to pull out individual items in the sublist
           # directly to variables. A really nice python feature
           #
           # Now we just need to draw our box
           drawing.rectangle((x,y,x+w,y+h), outline="red")
        display(img_initial)
        最初的圖像是這樣的:

        然后在繪制邊界框后,我們得到:

        如我們所見,我們設法正確地獲得了四個面,但是我們還發現了窗后的“鬼”……裁剪臉部以分離圖像我們還可以裁剪臉部以分離圖像for x,y,w,h in faces:

           img_initial.crop((x,y,x+w,y+h))
           display(img_initial.crop((x,y,x+w,y+h)))
        例如,我們得到的第一張臉是:

        注意:如果你想從硬盤讀取圖像,則只需鍵入以下三行:# read image from the PC
        initial_img=Image.open('my_image.jpg')
        img = cv.imread('my_image.jpg')
        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        OpenCV中的人臉檢測視頻這篇文章是一個實際示例,說明了我們如何將OpenCV]與Python結合使用來檢測視頻中的人臉。在上一篇文章中,我們解釋了如何在Tensorflow中應用對象檢測和OpenCV中的人臉檢測。通常,計算機視覺和對象檢測是人工智能中的熱門話題。例如考慮自動駕駛汽車,該自動駕駛汽車必須連續檢測周圍的許多不同物體(行人,其他車輛,標志等)。如何錄制人臉檢測視頻在以下示例中,我們將USB攝像頭應用到人臉檢測,然后將視頻寫入.mp4文件。如你所見,OpenCV能夠檢測到面部,并且當它隱藏在手后時,OpenCV會丟失它。import cv2
        # change your path to the one where the haarcascades/haarcascade_frontalface_default.xml is
        face_cascade = cv2.CascadeClassifier('../DATA/haarcascades/haarcascade_frontalface_default.xml')

        cap = cv2.VideoCapture(0)

        width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

        # MACOS AND LINUX: *'XVID' (MacOS users may want to try VIDX as well just in case)
        # WINDOWS *'VIDX'
        writer = cv2.VideoWriter('myface.mp4', cv2.VideoWriter_fourcc(*'XVID'),25, (width, height))


        while True:
           
           ret, frame = cap.read(0)
             
           frame = detect_face(frame)
           writer.write(frame)
         
           cv2.imshow('Video Face Detection', frame)
           # escape button to close it
           c = cv2.waitKey(1)
           if c == 27:
               break
               
        cap.release()
        writer.release()
        cv2.destroyAllWindows()
        計算機視覺代碼的輸出只需幾行代碼即可通過動態人臉檢測錄制該視頻。如果你運行上面的代碼塊,你將獲得類似的視頻。

        聲明: 本文由入駐維科號的作者撰寫,觀點僅代表作者本人,不代表OFweek立場。如有侵權或其他問題,請聯系舉報。

        發表評論

        0條評論,0人參與

        請輸入評論內容...

        請輸入評論/評論長度6~500個字

        您提交的評論過于頻繁,請輸入驗證碼繼續

        暫無評論

        暫無評論

          掃碼關注公眾號
          OFweek人工智能網
          獲取更多精彩內容
          文章糾錯
          x
          *文字標題:
          *糾錯內容:
          聯系郵箱:
          *驗 證 碼:

          粵公網安備 44030502002758號

          主站蜘蛛池模板: 91日韩在线| 亚洲图片在线| 亚洲最大成人| 奇骏影院在线观看免费版| 午夜激情网站| 色性av| 精品国模无码| 7777精品伊人久久久大香价格| 丰满熟女人妻中出系列| 无码精品人妻| 91视频污| 十八禁成人网站| 亚卅精品| 传媒视频??高清一区传媒| 玖草视频在线观看| 日本大色情www成人亚洲| 府谷县| 中文字幕?自拍| 激情图区| 渭南市| 国产九九| 亚洲色网导航| 安吉县| 欧美黑人一区| 91乱子伦国产乱子伦海的味道| 91.www| 91制片厂天美传媒网站进入| 男女动图视频网站在线播放| 91视频精品| 启东市| 陆河县| 91瑟瑟| 黄片不卡| 国产AV中文字幕| 欧美A级视频| 永久免费看mv网站入口| 91综合网| 91日韩| 日日干夜夜撸| 南靖县| 怀宁县|