我在 rgb 或 opencv bgr 中遇到了一些问题
我想做的是找到某些图片的 bgr 的整体值 但是每次我运行程序而不用完全相同的图片更改任何内容时,bgr 的值都会不断变化..
这就是我如何编写代码来查找 bgr 的值
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace std;
char path[255];
int main( int argc, char** argv )
{
IplImage *red[50];
IplImage *green[50];
IplImage *blue[50];
for(int i = 1; i <= 50; i++)
{
IplImage *img;
sprintf(path, "C:\\picture (%01).bmp", i);
img = cvLoadImage(path);
red[i] = cvCreateImage(cvGetSize(img), 8, 1);
green[i] = cvCreateImage(cvGetSize(img), 8, 1);
blue[i] = cvCreateImage(cvGetSize(img), 8, 1);
cvSplit(img, blue[i], green[i], red[i], NULL);
cvReleaseImage(&img);
int total = (int)(blue[i]) + (int)(green[i]) + (int)(red[i]);
cout << total << endl;
cvWaitKey(1);
}
cvWaitKey(0);
return 0;
}
最佳答案
我不确定你是如何实现从 IplImage
到 int
的类型转换的?
int total = (int)(blue[i]) + (int)(green[i]) + (int)(red[i]);
但您当然需要对每个 channel (而不是逐个图像)逐个像素求和以找到整体值。
关于c++ - opencv - rgb值不断变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17486352/