c++ - 按位 & 运算符返回 255

标签 c++ opencv

我正在使用按位 & 运算符,但我得到的结果不是 1 和 0,而是 255 和 0。可能是什么原因? 代码是

 cv::Mat TL_k_idx = ((orientation_map.col(0)<=(quad_coords[0]+quad_coords[2])/2) & (orientation_map.col(1)<=(quad_coords[1]+quad_coords[3])/2));
cout<<TL_k_idx;

The output of TL_k_idx is:
255 255 255 255 0 0............

orientation_map是Mat数据类型,quad_coords是数组,我做错了什么?

在使用逻辑运算符 && 时出现错误

error: no match for ‘operator&&’ in ‘cv::operator<=(const cv::Mat&, double)((double)((*
(quad_coords) + *(quad_coords + 8u)) / 2)) && cv::operator<=(const cv::Mat&, double)((double)((*
(quad_coords + 4u) + *(quad_coords + 12u)) / 2))’|

最佳答案

您不应期望按位 and 为 0 或 1。

下面是 255 的情况:

a = 255 & 255 // then a = 255;

举几个例子

Example 1    11111111 & 11111111 = 11111111 or 255

Example 2: 01010101 & 00000111 = 101 or 5.

http://en.wikipedia.org/wiki/Bitwise_operations_in_C

关于c++ - 按位 & 运算符返回 255,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18395579/

相关文章:

c++ - 如何将opencv mat图像转换为gdi位图

c++ - C++项目: Where to define global variable with function

c++ - 非阻塞控制台输入 C++

python - std::vector 到 boost::python::list 而不复制数据

c++ - C++串联;字符串+双;运算符+与运算符+ =

python - 计算机视觉 : Creating mask of hand using OpenCv and Python

opencv - 匹配不同图像中同一对象的两个轮廓

c++ - 阻止通过 ifstream 对象从 FIFO 读取

java - OpenCV Java : how to find connected components of image in OpenCv JAVA

image-processing - 实时 Cuda 图像处理建议