如何在整行或整列中使用位运算符? 我现在用C++ OpenCV来查看图像处理。我需要在矩阵的每一列或每一行上加上“或”。比如说 A =[1 0 1 0; 0 0 0 0; 0 1 0 0]; I need to take for row Ans = [1 1 1 0]; for column Ans =[1; 0; 1];
我找了很久,但我想我找不到了。请帮帮我 如果将数据拆分为行和列,如下所示:如何在整行或整列中使用位运算符? 我现在用C++ OpenCV来查看图像处理。我需要在矩阵的每一列或每一行上加上“或”。比如说 A =[1 0 1 0; 0 0 0 0; 0 1 0 0]; I need to take for row Ans = [1 1 1 0]; for column Ans =[1; 0; 1];,c++,opencv,row,bit-manipulation,bitwise-or,C++,Opencv,Row,Bit Manipulation,Bitwise Or,我找了很久,但我想我找不到了。请帮帮我 如果将数据拆分为行和列,如下所示: const int rows = 3; const int cols = 4; int A[rows][cols] = {1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0}; 然后您可以使用: int ansrow[cols], anscol[rows]; int i, j; for (i = 0; i < cols; i++ ){ ansrow[i] = 0; for (j = 0
const int rows = 3;
const int cols = 4;
int A[rows][cols] = {1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0};
然后您可以使用:
int ansrow[cols], anscol[rows];
int i, j;
for (i = 0; i < cols; i++ ){
ansrow[i] = 0;
for (j = 0; j < rows; j++ ){
ansrow[i] |= A[i][j];
}
}
for (i = 0; i < rows; i++ ){
anscol[i] = 0;
for (j = 0; j < cols; j++ ){
anscol[i] |= A[i][j];
}
}
int-ansrow[cols],anscol[rows];
int i,j;
对于(i=0;i
给定Ans_行是cv::Mat和Ans_行。cols==Mat.cols,您可以轻松编写:
Mat a = Ans_row | mat.row(i); //expects: Ans_row.cols== mat.cols, Ans_row.rows==1
以及:
rgb[1]是我的矩阵
cv::Size s = rgb[1].size();
bitwise_or(rgb[1].col(1),rgb[1].col(2),asd1);
for(i = 3;i<s.width;i++)
{
bitwise_or(rgb[1].col(i),asd1,asd1);
}
cv::Size s=rgb[1].Size();
按位_或(rgb[1]。列(1),rgb[1]。列(2),asd1);
对于(i=3;我只是使用<代码> STD::转换< /代码>),您是不是在寻找一个巨大的矩阵,并在许多处理器上使用OpenCV进行分配?或者,您是否希望使用标准C++来执行标准数据类型?
cv::Size s = rgb[1].size();
bitwise_or(rgb[1].col(1),rgb[1].col(2),asd1);
for(i = 3;i<s.width;i++)
{
bitwise_or(rgb[1].col(i),asd1,asd1);
}