你好,楼主,我在3.5.2例程中,发现我的电脑编辑效果只有单通道的能正常显示,3通道的则无法显示,请问您知道这是什么原因吗?下面是我的代码
- #include <QCoreApplication>
- #include <iostream>
- #include "opencv2/core.hpp"
- #include "opencv2/opencv.hpp"
- using namespace std;
- using namespace cv;
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
- Mat grayim(600,800,CV_8UC1);
- Mat colorim(600,800,CV_8UC3);
- //遍历所有的像素,并设置像素值
- MatIterator_<uchar> grayit,grayend;
- for(grayit = grayim.begin<uchar>(),
- grayend = grayim.end<uchar>();
- grayit != grayend;++grayit)
- {
- *grayit = rand()%255;
- }
- //遍历所有像素值,并设置像素值
- MatIterator_<Vec3d>colorit,colorend;
- for(colorit = colorim.begin<Vec3d>(),
- colorend = colorim.end<Vec3d>();
- colorit != colorend;++colorit)
- {
- (*colorit)[0] = rand()%255;
- (*colorit)[1] = rand()%255;
- (*colorit)[2] = rand()%255;
- }
- imshow("grayim",grayim);
- imshow("colorim",colorim);
- waitKey(0);
- return 0;
- }
复制代码 |