久久久久久久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(計算邊界框重疊的百分比,用于圖像檢測器評估)
主站蜘蛛池模板: 97视频在线免费 | www.日本三级| 日本淫视频 | 亚洲精品日韩在线观看 | 日本久久久影视 | 97人人澡人人爽91综合色 | 日本aⅴ中文字幕 | 中文字幕一二三区 | 国产一区二区 | 国产精品无码永久免费888 | 91久久综合 | 91av在线免费播放 | 欧美aaaaa| 国产精品激情 | 免费黄色av | 久久亚洲综合 | 黄色福利 | 精品乱人伦一区二区三区 | 午夜精品久久久久久久99黑人 | 91国内精精品久久久久久婷婷 | 在线中文字幕av | 女人牲交视频一级毛片 | 国产精品国产三级国产aⅴ中文 | 日韩精品一区二区三区视频播放 | 男女网站免费观看 | 国产一区二区观看 | 国产日韩欧美一区 | 玖操| 色婷婷av777 av免费网站在线 | 日本激情视频中文字幕 | 国产综合精品一区二区三区 | 7777在线视频 | 男女羞羞视频在线免费观看 | 国产在线对白 | 美女国内精品自产拍在线播放 | a级黄色网 | 国产精品国产精品国产专区不卡 | 亚洲精品99久久久久久 | 99久久久国产精品免费消防器 | 极情综合网 | 亚洲欧美日韩系列 |