1
我嘗試運行下面的代碼:OpenCV的INRANGE()函數
#include<opencv\cv.h>
#include<opencv\highgui.h>
using namespace cv;
int main() {
VideoCapture cap;
cap.open(0);
while (1) {
Mat src;
Mat threshold;
cap.read(src);
inRange(src, Scalar(0, 0, 0), Scalar(255, 0, 0), threshold);
imshow("thr", threshold);
imshow("hsv", src);
waitKey(33);
}
return 0;
}
但好像它不篩選,因爲只有當我運行的代碼出現一個空白窗口。
如何獲取該代碼來檢測紅色?
你能看到你的源圖像嗎?或一個黑色的窗口? –
謝謝你的回覆,我正確地看到源圖片。 – Danaro
你忘了轉換成hsv的'src'圖像; D另外,在OpenCV中使用BGR,而不是RGB,因此你要設置藍色通道。因此,在BGR中,你的閾值應該是這樣的:inRange(src,Scalar(0,0,0),Scalar(50,50,255),threshold);'更好地使用HSV色彩空間,參見重複 – Miki