//因為進行8位儲存,所以除以2
const
int max_value =
255;
const cv:
:string window_capture_name =
"video capture"
;const cv:
:string window_detection_name =
"object detection"
;int low_h =
0, low_s =
0, low_v =0;
int high_h = max_value_h, high_s = max_value, high_v = max_value;
static
void
on_low_h_thresh_trackvbar
(int
,void*)
static
void
on_high_h_thresh_trackbar
(int
,void*)
static
void
on_low_s_thresh_trackbar
(int
,void*)
static
void
on_high_s_thresh_trackbar
(int
,void*)
static
void
on_low_v_thresh_trackbar
(int
,void*)
static
void
on_high_v_thresh_trackvar
(int
,void*)
intmain
(void
) cv:
:cvtcolor
(frame,frame_hsv,cv:
:color_bgr2hsv)
;//轉化到hsv空間
//進行閾值操作,輸出影象為cv_8uc1
inrange
(frame_hsv,
scalar
(low_h,low_s,low_v)
,scalar
(high_h,high_s,high_v)
,frame_threshold)
;imshow
(window_capture_name,frame)
;imshow
(window_detection_name,frame_threshold)
;char key=
(char
)waitkey(30
);//每等待30ms,如果是esc,退出
if(key ==27)
break;}
return0;
};結果:
void cv::inrange
( inputarray src, //輸入影象
inputarray lowerb, //低閾值
inputarray upperb, //高閾值
outputarray dst //輸出影象(same size as src),cv_8uc1)
dst(i) 為1,如果輸入影象的畫素在lowerb和upperb形成的 1d,2d,3d的box裡面,否則為0,
比如1d,則lowerb和upperb只是一維值,如果是3d,則lowerb和upperb只是三維值,輸入影象也是三維,只要每個元素再lowerb和upperb組成的3d box裡面,輸出就是1,所以輸出是cv_8uc1
基本閾值操作
1 閾值二值化 threshold binary 2 閾值反二值化 threshold binary inverted 3 截斷 truncate 將超過閾值部分設定為閾值 4 閾值取零 threshold to zero 將小於閾值的部分取零 5 閾值反取零 threshold to zero i...
opencv 閾值操作
閾值分割5種方法 尋找閾值2種方法 double cv threshold inputarray src,outputarray dst,double thresh,double maxval,int type 引數 含義src 輸入,要求是單通道影象 thresh 門限值maxval 超過門限的畫...
基本的閾值操作
示例 說明結果 二分閾值 d st x y cvtcolor src,src gray,color bgr2gray convert the image to gray namedwindow window name,window autosize create a window to displa...