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

使用 Python OpenCV 查找圖像中的極端外部點

Find extreme outer points in image with Python OpenCV(使用 Python OpenCV 查找圖像中的極端外部點)
本文介紹了使用 Python OpenCV 查找圖像中的極端外部點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有這個雕像的圖像.

我正在嘗試找到雕像的頂部、底部、左側(cè)和最右側(cè)的點.有沒有辦法測量每邊的邊緣以確定雕像上的最外點?我想得到每一邊的 (x,y) 坐標.我嘗試使用 cv2.findContours()cv2.drawContours() 來獲得雕像的輪廓.

導(dǎo)入 cv2img = cv2.imread('statue.png')灰色 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)輪廓 = cv2.findContours(灰色,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[0]cv2.drawContours(img, 輪廓, -1, (0, 200, 0), 3)cv2.imshow('img', img)cv2.waitKey()

解決方案

這是一個潛在的方法:

  • 將圖像轉(zhuǎn)換為 或 argmax() 像這樣確定外左、右、上、下坐標

    left = tuple(c[c[:, :, 0].argmin()][0])對 = 元組(c[c[:, :, 0].argmax()][0])top = tuple(c[c[:, :, 1].argmin()][0])底部 = 元組(c[c[:, :, 1].argmax()][0])

    這是結(jié)果

    <塊引用>

    左:(162, 527)

    <塊引用>

    右:(463, 467)

    <塊引用>

    頂部:(250, 8)

    <塊引用>

    底部:(381, 580)

    導(dǎo)入 cv2將 numpy 導(dǎo)入為 np# 加載圖像,灰度,高斯模糊,閾值圖像 = cv2.imread('1.png')灰色 = cv2.cvtColor(圖像,cv2.COLOR_BGR2GRAY)模糊 = cv2.GaussianBlur(灰色, (3,3), 0)thresh = cv2.threshold(模糊, 220, 255, cv2.THRESH_BINARY_INV)[1]# 尋找輪廓cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)cnts = cnts[0] 如果 len(cnts) == 2 否則 cnts[1]c = max(cnts, key=cv2.contourArea)# 獲取外坐標left = tuple(c[c[:, :, 0].argmin()][0])對 = 元組(c[c[:, :, 0].argmax()][0])top = tuple(c[c[:, :, 1].argmin()][0])底部 = 元組(c[c[:, :, 1].argmax()][0])# 在圖像上畫點cv2.drawContours(圖像, [c], -1, (36, 255, 12), 2)cv2.circle(圖像, 左, 8, (0, 50, 255), -1)cv2.circle(圖像, 右, 8, (0, 255, 255), -1)cv2.circle(圖像, 頂部, 8, (255, 50, 0), -1)cv2.circle(圖像, 底部, 8, (255, 255, 0), -1)print('left: {}'.format(left))print('right: {}'.format(right))print('top: {}'.format(top))print('bottom: {}'.format(bottom))cv2.imshow('thresh', thresh)cv2.imshow('圖像', 圖像)cv2.waitKey()

    I have this image of a statue.

    I'm trying to find the top, bottom, left, and right most points on the statue. Is there a way to measure the edge of each side to determine the outer most point on the statue? I want to get the (x,y) coordinate of each side. I have tried to use cv2.findContours() and cv2.drawContours() to get an outline of the statue.

    import cv2
    
    img = cv2.imread('statue.png')
    
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    
    contours = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[0]
    cv2.drawContours(img, contours, -1, (0, 200, 0), 3)
    
    cv2.imshow('img', img)
    cv2.waitKey()
    

    解決方案

    Here's a potential approach:

    • Convert image to grayscale and Gaussian blur

    • Threshold to obtain a binary image

    • Find contours

    • Obtain outer coordinates


    After converting to grayscale and blurring image, we threshold to get a binary image

    Now we find contours using cv2.findContours(). Since OpenCV uses Numpy arrays to encode images, a contour is simply a Numpy array of (x,y) coordinates. We can slice the Numpy array and use argmin() or argmax() to determine the outer left, right, top, and bottom coordinates like this

    left = tuple(c[c[:, :, 0].argmin()][0])
    right = tuple(c[c[:, :, 0].argmax()][0])
    top = tuple(c[c[:, :, 1].argmin()][0])
    bottom = tuple(c[c[:, :, 1].argmax()][0])
    

    Here's the result

    left: (162, 527)

    right: (463, 467)

    top: (250, 8)

    bottom: (381, 580)

    import cv2
    import numpy as np
    
    # Load image, grayscale, Gaussian blur, threshold
    image = cv2.imread('1.png')
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray, (3,3), 0)
    thresh = cv2.threshold(blur, 220, 255, cv2.THRESH_BINARY_INV)[1]
    
    # Find contours
    cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    cnts = cnts[0] if len(cnts) == 2 else cnts[1]
    c = max(cnts, key=cv2.contourArea)
    
    # Obtain outer coordinates
    left = tuple(c[c[:, :, 0].argmin()][0])
    right = tuple(c[c[:, :, 0].argmax()][0])
    top = tuple(c[c[:, :, 1].argmin()][0])
    bottom = tuple(c[c[:, :, 1].argmax()][0])
    
    # Draw dots onto image
    cv2.drawContours(image, [c], -1, (36, 255, 12), 2)
    cv2.circle(image, left, 8, (0, 50, 255), -1)
    cv2.circle(image, right, 8, (0, 255, 255), -1)
    cv2.circle(image, top, 8, (255, 50, 0), -1)
    cv2.circle(image, bottom, 8, (255, 255, 0), -1)
    
    print('left: {}'.format(left))
    print('right: {}'.format(right))
    print('top: {}'.format(top))
    print('bottom: {}'.format(bottom))
    cv2.imshow('thresh', thresh)
    cv2.imshow('image', image)
    cv2.waitKey()
    

    這篇關(guān)于使用 Python OpenCV 查找圖像中的極端外部點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應(yīng)用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产视频久 | 亚洲一区二区精品视频 | 99国内精品| 黑人精品欧美一区二区蜜桃 | 91久久久精品国产一区二区蜜臀 | 99精品国产一区二区三区 | 国产视频久久 | 在线播放一区二区三区 | 激情a| 亚洲一区二区三区四区五区午夜 | 男女视频网站 | 欧美 日韩 国产 成人 在线 91 | 精品日韩一区二区三区av动图 | 欧美日韩国产中文字幕 | 日本三级网站在线观看 | 亚洲欧美一区二区三区视频 | 一区二区三区四区在线视频 | 一区二区三区四区不卡视频 | 欧美精品欧美精品系列 | av不卡一区 | www4虎| 久久伊人精品一区二区三区 | 三级av在线 | 福利社午夜影院 | 精品亚洲一区二区 | 国产一区二区在线视频 | 福利片一区二区 | 一区二区三区四区五区在线视频 | 一区二区不卡视频 | 国产精品伦理一区 | 欧美日韩在线观看一区 | 看a网站 | 免费国产视频 | 成人三级在线观看 | 精品欧美一区二区三区久久久 | 91久久视频| 日韩高清成人 | 91最新视频 | 国产精品免费观看视频 | 亚洲巨乳自拍在线视频 | 美女久久|