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

如何在圖像的多個矩形邊界框中應用閾值?

How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
本文介紹了如何在圖像的多個矩形邊界框中應用閾值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的問題是:我有圖像中對象周圍的邊界框的 ROI.ROI 由 Faster R-CNN 獲得.現在我想要的是應用閾值來使對象準確地包含在邊界框中.該圖像的 ROI 由 Faster RCNN 獲得.

所以,在獲得 ROI 后,我只從圖像中選擇 ROI 并粘貼到相同大小和尺寸的黑色圖像上,從而產生以下圖像.讓我們說

正如您所見,盒子是矩形的,因此在某些地方它會覆蓋一些背景區域以及尖刺.那么,如何應用閾值處理來僅使尖峰和其他像素變為黑色?

編輯:我已將鏈接添加到問題中第一張圖像的 ROI 文本文件

將 numpy 導入為 np導入簡歷2圖像 = cv2.imread('1.jpg')結果 = image.copy()圖像 = cv2.cvtColor(圖像,cv2.COLOR_BGR2HSV)下 = np.array([18, 0, 0])上 = np.array([179, 255, 255])掩碼 = cv2.inRange(圖像,下,上)結果= cv2.bitwise_and(結果,結果,掩碼=掩碼)cv2.imshow('結果', 結果)cv2.imwrite('result.png', 結果)cv2.waitKey()

您可以使用 HSV 顏色閾值腳本來隔離所需的顏色范圍

導入 cv2導入系統將 numpy 導入為 np什么都沒有(x):經過# 創建一個窗口cv2.namedWindow('圖像')# 創建顏色變化的軌跡欄cv2.createTrackbar('HMin','image',0,179,nothing) # Opencv 的色調為 0-179cv2.createTrackbar('SMin','image',0,255,nothing)cv2.createTrackbar('VMin','image',0,255,nothing)cv2.createTrackbar('HMax','image',0,179,nothing)cv2.createTrackbar('SMax','image',0,255,nothing)cv2.createTrackbar('VMax','image',0,255,nothing)# 設置 MAX HSV 軌跡欄的默認值.cv2.setTrackbarPos('HMax', '圖像', 179)cv2.setTrackbarPos('SMax', '圖像', 255)cv2.setTrackbarPos('VMax', 'image', 255)# 初始化檢查 HSV 最小/最大值是否改變hMin = sMin = vMin = hMax = sMax = vMax = 0phMin = psMin = pvMin = phMax = psMax = pvMax = 0img = cv2.imread('1.jpg')輸出 = img等待時間 = 33而(1):# 獲取所有軌跡欄的當前位置hMin = cv2.getTrackbarPos('HMin','image')sMin = cv2.getTrackbarPos('SMin','image')vMin = cv2.getTrackbarPos('VMin','image')hMax = cv2.getTrackbarPos('HMax','image')sMax = cv2.getTrackbarPos('SMax','image')vMax = cv2.getTrackbarPos('VMax','image')# 設置要顯示的最小和最大 HSV 值較低 = np.array([hMin, sMin, vMin])上 = np.array([hMax, sMax, vMax])# 創建 HSV 圖像和閾值到一個范圍內.hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)掩碼 = cv2.inRange(hsv, 下, 上)輸出 = cv2.bitwise_and(img,img, mask= mask)# 如果 HSV 值發生變化,打印如果((phMin!= hMin)|(psMin!= sMin)|(pvMin!= vMin)|(phMax!= hMax)|(psMax!= sMax)|(pvMax!= vMax)):print("(hMin = %d , sMin = %d, vMin = %d), (hMax = %d , sMax = %d, vMax = %d)" % (hMin , sMin , vMin, hMax, sMax, vMax))phMin = hMinpsMin = sMinpvMin = vMinphMax = hMaxpsMax = sMaxpvMax = vMax# 顯示輸出圖像cv2.imshow('圖像',輸出)# 等待更長的時間以防止視頻凍結.如果 cv2.waitKey(waitTime) &0xFF == ord('q'):休息cv2.destroyAllWindows()

這是原始圖像上的結果

My question is that: I have ROI's for the bounding boxes around the objects in an image. The ROI's are obtained by the Faster R-CNN. Now what I want is to apply the thresholding to get the object accurately contained within the bounding box. The ROI of this image was got by the Faster RCNN.

So, After getting the ROI's, I only selected ROI from the image and pasted on the black image of the same size and dimension which result in the following image.let say

As you can see that boxes are rectangular so in some places it covers some background area along with spikes. So, how can I apply thresholding to get only the spikes and other pixels turn to black?

EDIT: I've added the link to the ROI text file of the first image in the question

ROI file for first image

解決方案

Color thresholding using cv2.inRange() should work here. I'm assuming you want to isolate the green area

Here's the main idea

  • Convert image to HSV format since it is easier to represent color than RBG
  • Perform color segmentation with a lower/upper threshold

You could also perform morphological operations to smooth or remove noise after obtaining the mask


import numpy as np
import cv2

image = cv2.imread('1.jpg')
result = image.copy()
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower = np.array([18, 0, 0])
upper = np.array([179, 255, 255])
mask = cv2.inRange(image, lower, upper)
result = cv2.bitwise_and(result,result, mask=mask)
cv2.imshow('result', result)
cv2.imwrite('result.png', result)
cv2.waitKey()

You can use a HSV color thresholder script to isolate the desired color range

import cv2
import sys
import numpy as np

def nothing(x):
    pass

# Create a window
cv2.namedWindow('image')

# create trackbars for color change
cv2.createTrackbar('HMin','image',0,179,nothing) # Hue is from 0-179 for Opencv
cv2.createTrackbar('SMin','image',0,255,nothing)
cv2.createTrackbar('VMin','image',0,255,nothing)
cv2.createTrackbar('HMax','image',0,179,nothing)
cv2.createTrackbar('SMax','image',0,255,nothing)
cv2.createTrackbar('VMax','image',0,255,nothing)

# Set default value for MAX HSV trackbars.
cv2.setTrackbarPos('HMax', 'image', 179)
cv2.setTrackbarPos('SMax', 'image', 255)
cv2.setTrackbarPos('VMax', 'image', 255)

# Initialize to check if HSV min/max value changes
hMin = sMin = vMin = hMax = sMax = vMax = 0
phMin = psMin = pvMin = phMax = psMax = pvMax = 0

img = cv2.imread('1.jpg')
output = img
waitTime = 33

while(1):

    # get current positions of all trackbars
    hMin = cv2.getTrackbarPos('HMin','image')
    sMin = cv2.getTrackbarPos('SMin','image')
    vMin = cv2.getTrackbarPos('VMin','image')

    hMax = cv2.getTrackbarPos('HMax','image')
    sMax = cv2.getTrackbarPos('SMax','image')
    vMax = cv2.getTrackbarPos('VMax','image')

    # Set minimum and max HSV values to display
    lower = np.array([hMin, sMin, vMin])
    upper = np.array([hMax, sMax, vMax])

    # Create HSV Image and threshold into a range.
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, lower, upper)
    output = cv2.bitwise_and(img,img, mask= mask)

    # Print if there is a change in HSV value
    if( (phMin != hMin) | (psMin != sMin) | (pvMin != vMin) | (phMax != hMax) | (psMax != sMax) | (pvMax != vMax) ):
        print("(hMin = %d , sMin = %d, vMin = %d), (hMax = %d , sMax = %d, vMax = %d)" % (hMin , sMin , vMin, hMax, sMax , vMax))
        phMin = hMin
        psMin = sMin
        pvMin = vMin
        phMax = hMax
        psMax = sMax
        pvMax = vMax

    # Display output image
    cv2.imshow('image',output)

    # Wait longer to prevent freeze for videos.
    if cv2.waitKey(waitTime) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

Here's the result on the original image

這篇關于如何在圖像的多個矩形邊界框中應用閾值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
Calculating percentage of Bounding box overlap, for image detector evaluation(計算邊界框重疊的百分比,用于圖像檢測器評估)
主站蜘蛛池模板: 精品一区二区电影 | 久久国产亚洲 | 尤物在线视频 | 91精品国产一区二区三区蜜臀 | 国产精久久久久久 | 91成人影院 | 精品视频在线播放 | 免费成人在线网站 | 亚洲成人久久久 | 国产成人久久精品一区二区三区 | 欧美一级黄色免费 | 欧美高清免费 | 国产激情在线看 | 日韩精品一区二区三区在线播放 | 精品三级在线观看 | 国产中文字幕在线观看 | 在线观看中文字幕av | 在线视频日韩 | 日批免费看 | 欧美成人一区二免费视频软件 | 亚洲手机视频在线 | eeuss国产一区二区三区四区 | 一区二区三区免费 | 三级在线视频 | 夜夜操av| 欧美日韩黄色一级片 | 99精品亚洲国产精品久久不卡 | 亚洲日本成人 | 欧美一区二区视频 | 天天精品综合 | 国产精品资源在线观看 | 天堂一区 | 国产一区二区 | 91精品国产91综合久久蜜臀 | 亚洲在线成人 | 欧美国产视频 | 亚洲综合久久精品 | 一级日韩 | 国产一区精品 | 美日韩免费视频 | 米奇狠狠鲁 |