我有一个矩阵,该矩阵是300列和行1。当我cout <<
它,我得到:
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
...这是我期望/希望的形式。
问题
然而,当我通过它循环,我想每个单独的值的每个迭代。然而,相反,我得到一个稍微不同的顺序(有时它是非常相似的,虽然)。
代码
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgcodecs/imgcodecs.hpp"
using namespace std;
using namespace cv;
int main(){
Mat test(1,300,CV_8UC1, 255);
cout << test;
Mat frame, grayFrame,threshFrame,smaller;
VideoCapture cap(0);
while(true){
cap.read(frame);
cvtColor(frame, grayFrame, cv::COLOR_RGB2GRAY);
threshold(grayFrame, threshFrame, 160, 255, THRESH_BINARY);
smaller = threshFrame(Rect(0,0,300,1));
cout << smaller;
for(int x=0;x<smaller.cols;x++){
int color = smaller.at<Vec3b>(x,1)[0];
cout << color;
}
break;
}
}
...这不符合0和255秒的原始矩阵完全相同的顺序怪异输出:
00000000000000000000000000000000000000000000000000000000000000000000000000000000000002552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552552550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
矩阵有许多0起初只有几乎255秒,因为循环输出有很多的255s,并没有太多的开始0。从本质上讲,我想循环显示第一个矩阵,并为每次迭代获取每个值。所以0,0,255,255 ...等
你不打印你的值之间的空格... – jaggedSpire
我的问题没有任何东西o与空间,数据结构。一个是数组,一个是int输出...我的意思是ORDER。你会注意到订单仍然不同,原来的开始“0,0,255”和循环开始“255,255,255” –
所以它是。你会提供[MCVE](http://stackoverflow.com/help/mcve)吗? – jaggedSpire