无法理解表达式Vxy和Vxy_nocast的结果
uchar init_m0[] = {10,10,30};
cv::Mat m0(3,1,CV_8UC1,init_m0,sizeof(uchar));
uchar& Vxy = m0.at<uchar>(0);
uchar& Vxy_nocast = m0.at<uchar>(1);
std::cout << m0 << std::endl;
Vxy = cv::saturate_cast<uchar>((Vxy-128)*2 + 128);
Vxy_nocast = (Vxy_nocast-128)*2 + 128;
std::cout << m0 << std::endl;
结果
[ 10;
10;
30]
[ 0;
148;
30]
答案 0 :(得分:1)
-- empty temp table with identical structure
CREATE TABLE tbl_tmp AS TABLE tbl LIMIT 0;
-- ... except for the int / text column
ALTER TABLE tbl_tmp ALTER col_int TYPE text;
COPY tbl_tmp ...;
INSERT INTO tbl -- identical number and names of columns guaranteed
SELECT col1, col2, NULLIF(col_int, '')::int -- list all columns in order here
FROM tbl_tmp;
。 (10-128)*2 + 128 = -108
是对unsigned char的饱和转换,unsigned char只能是&gt; = 0.正常的uchar转换,如果你什么都不指定就会隐式发生,只需重新解释就会将负值换算为正数位,-108在2的补码二进制中是cv::saturate_cast<uchar>
,与148相同(并且它还将包围更大的值,例如257到1)。相反,饱和的强制转换将负值转换为0,在该类型的最小值为0时饱和(同样正值将在最大值为255时饱和)。
有关详细信息,请参阅saturation arithmetic。