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

使用 cv::inRange (OpenCV) 為顏色檢測選擇正確的 HS

Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)(使用 cv::inRange (OpenCV) 為顏色檢測選擇正確的 HSV 上下邊界)
本文介紹了使用 cv::inRange (OpenCV) 為顏色檢測選擇正確的 HSV 上下邊界的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一張帶有橙色蓋子位置的咖啡罐的圖像,我想找到它.這是 .

I have an image of a coffee can with an orange lid position of which I want to find. Here is it .

gcolor2 實用程序顯示蓋子中心的 HSV 為 (22, 59, 100).問題是如何選擇顏色的界限呢?我嘗試了 min = (18, 40, 90) 和 max = (27, 255, 255),但得到了意外

gcolor2 utility shows HSV at the center of the lid to be (22, 59, 100). The question is how to choose the limits of the color then? I tried min = (18, 40, 90) and max = (27, 255, 255), but have got unexpected

這是 Python 代碼:

Here is the Python code:

import cv

in_image = 'kaffee.png'
out_image = 'kaffee_out.png'
out_image_thr = 'kaffee_thr.png'

ORANGE_MIN = cv.Scalar(18, 40, 90)
ORANGE_MAX = cv.Scalar(27, 255, 255)
COLOR_MIN = ORANGE_MIN
COLOR_MAX = ORANGE_MAX

def test1():
    frame = cv.LoadImage(in_image)
    frameHSV = cv.CreateImage(cv.GetSize(frame), 8, 3)
    cv.CvtColor(frame, frameHSV, cv.CV_RGB2HSV)
    frame_threshed = cv.CreateImage(cv.GetSize(frameHSV), 8, 1)
    cv.InRangeS(frameHSV, COLOR_MIN, COLOR_MAX, frame_threshed)
    cv.SaveImage(out_image_thr, frame_threshed)

if __name__ == '__main__':
    test1()

推薦答案

問題一: 不同的應用程序對 HSV 使用不同的尺度.例如 gimp 使用 H = 0-360, S = 0-100 和 V = 0-100.但是 OpenCV 使用 H: 0-179, S: 0-255, V: 0-255.在這里,我在 gimp 中得到了 22 的色調值.所以我拿了一半,11,并為此定義了范圍.即(5,50,50) - (15,255,255).

Problem 1 : Different applications use different scales for HSV. For example gimp uses H = 0-360, S = 0-100 and V = 0-100. But OpenCV uses H: 0-179, S: 0-255, V: 0-255. Here i got a hue value of 22 in gimp. So I took half of it, 11, and defined range for that. ie (5,50,50) - (15,255,255).

問題 2: 而且,OpenCV 使用 BGR 格式,而不是 RGB.因此,如下更改將 RGB 轉換為 HSV 的代碼:

Problem 2: And also, OpenCV uses BGR format, not RGB. So change your code which converts RGB to HSV as follows:

cv.CvtColor(frame, frameHSV, cv.CV_BGR2HSV)

現在運行它.我得到如下輸出:

Now run it. I got an output as follows:

希望這是您想要的.有一些錯誤檢測,但它們很小,因此您可以選擇最大的輪廓即您的蓋子.

Hope that is what you wanted. There are some false detections, but they are small, so you can choose biggest contour which is your lid.

正如 Karl Philip 在他的評論中所說,添加新代碼會很好.但是只有一行的變化.因此,我想在新的 cv2 模塊中添加相同的代碼,以便用戶可以比較新的 cv2 模塊的易用性和靈活性.

As Karl Philip told in his comment, it would be good to add new code. But there is change of only a single line. So, I would like to add the same code implemented in new cv2 module, so users can compare the easiness and flexibility of new cv2 module.

import cv2
import numpy as np

img = cv2.imread('sof.jpg')

ORANGE_MIN = np.array([5, 50, 50],np.uint8)
ORANGE_MAX = np.array([15, 255, 255],np.uint8)

hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)

frame_threshed = cv2.inRange(hsv_img, ORANGE_MIN, ORANGE_MAX)
cv2.imwrite('output2.jpg', frame_threshed)

它給出與上面相同的結果.但是代碼要簡單得多.

It gives the same result as above. But code is much more simpler.

這篇關于使用 cv::inRange (OpenCV) 為顏色檢測選擇正確的 HSV 上下邊界的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 中文字幕在线免费观看 | 国产成人精品一区二区三区四区 | 中文一区 | 亚洲精品福利视频 | 午夜激情影院 | 国产精品视频免费观看 | 羞羞的视频在线看 | 国产精品综合一区二区 | 久久成| 老子午夜影院 | 午夜影晥 | 午夜国产 | 国产精品久久av | 午夜精 | 亚洲国产成人精品女人久久久 | 亚洲一区二区三区在线 | 久久国产传媒 | 黄一区二区三区 | 精品一区久久 | 欧美一区二区小视频 | 亚洲一区高清 | 国产成人高清 | 国产精品亚洲一区二区三区在线 | 日本一区二区不卡 | 伊人欧美视频 | 99综合| 久久久久久艹 | 综合九九| av网站在线播放 | 国产不卡在线观看 | 亚洲一区二区不卡在线观看 | 日本又色又爽又黄又高潮 | 波多野结衣一区二区 | 亚洲一区网站 | 亚洲中午字幕 | 日韩免费网站 | 久久久久久久国产精品 | 亚洲精品中文字幕 | 拍真实国产伦偷精品 | 色悠悠久 | 久久久精 |