簡體   English   中英

opencv閾值或不等於運算符

[英]opencv threshold or not equal operator

我的matlab代碼是

imTemp(imTemp ~= maxInd) = 0;

其中imTemp是100x100雙矩陣且maxInd == 1

我考慮過使用cv :: threshold http://docs.opencv.org/doc/tutorials/imgproc/threshold/threshold.html

但這並不能真正幫助我。
只有當src(x,y)> thresh ....做點什么
您能想到另一個可以實現此邏輯的openCV函數嗎?

您可以嘗試compare ,它可以使用CMP_EQ檢查矩陣和標量(或另一個矩陣)之間的CMP_EQ

不幸的是, compare具有令人討厭的功能,即滿足比較運算符的值設置為255而不是1或原始值,因此必須進行除法以獲得Matlab行為。

Mat imTemp = (Mat_<double>(3,3) << 9,7,4,4,9,6,2,0,1);
double maxInd = 9;
cout << "imTemp Original:" << endl;
cout << imTemp << endl;

compare(imTemp, Scalar(maxInd), imTemp, CMP_EQ);
imTemp = imTemp*maxInd/255;

cout << "imTemp Compared:" << endl;
cout << imTemp << endl;

輸出:

imTemp Original:
[9, 7, 4;
  4, 9, 6;
  2, 0, 1]
imTemp Compared:
[9, 0, 0;
  0, 9, 0;
  0, 0, 0]

您還可以直接使用比較運算符來獲得相同的結果(具有相同的255行為):

Mat imTemp = (imTemp == maxInd)*maxInd/255;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM