首页 \ 问答 \ 显示直方图openCV(Displaying histogram plot openCV)

显示直方图openCV(Displaying histogram plot openCV)

我有一个我计算过的图像的直方图。 我想将其显示为图像,以便我可以实际看到直方图。 我认为我的问题与缩放有关,虽然我对左上角的0,0开始的坐标系有点困惑。

int rows = channel.rows;
int cols = channel.cols;
int hist[256] = {0};
for(int i = 0; i<rows; i++)
{
    for(int k = 0; k<cols; k++ )
    {
        int value = channel.at<cv::Vec3b>(i,k)[0];
        hist[value] = hist[value] + 1;
    }
}

Mat histPlot = cvCreateMat(256, 500,CV_8UC1);
for(int i = 0; i < 256; i++)
{
    int mag = hist[i];
    line(histPlot,Point(i,0),Point(i,mag),Scalar(255,0,0));
}

namedWindow("Hist",1);
imshow("Hist",histPlot);

这是我创建直方图并显示结果的计算。 如果我在第二次循环中使用mag / 100,那么我会看到一些相似的情节(虽然是颠倒的)。 每当我调整图像的值时,我都会调用此方法,因此直方图也应该改变形状,这似乎不会发生。 任何帮助缩放直方图并正确显示它是值得赞赏的。


I have the histogram for an image which i have calculated. I want to display this as an image so that I can actually see the histogram. I think my problem is to do with scaling although i am slightly confused over the co ordinate system starting with 0,0 in the top left as well.

int rows = channel.rows;
int cols = channel.cols;
int hist[256] = {0};
for(int i = 0; i<rows; i++)
{
    for(int k = 0; k<cols; k++ )
    {
        int value = channel.at<cv::Vec3b>(i,k)[0];
        hist[value] = hist[value] + 1;
    }
}

Mat histPlot = cvCreateMat(256, 500,CV_8UC1);
for(int i = 0; i < 256; i++)
{
    int mag = hist[i];
    line(histPlot,Point(i,0),Point(i,mag),Scalar(255,0,0));
}

namedWindow("Hist",1);
imshow("Hist",histPlot);

This is my calculation for creating my histogram and displaying the result. If i do mag/100 in my second loop then i get some resemblance of a plot appearing (although upside down). I call this method whenever i adjust a value of my image, so the histogram should also change shape, which it doesn't appear to do. Any help in scaling the histogram and displaying it properly is appreciated.


原文:https://stackoverflow.com/questions/19916803
更新时间:2022-02-22 15:02

最满意答案

我相信你在课堂上遗漏了这个注释

@RunWith(SpringJUnit4ClassRunner.class)

您必须告诉junit它应该与Spring一起运行才能使注射工作

您还应该使用@AutoWired来声明属性loginService,并将xml中的bean重命名为loginService。

你的atrributes和bean名称必须相同,Spring为你绑定它!


I believe you are missing this annotation in your class

@RunWith(SpringJUnit4ClassRunner.class)

You must tell to junit that it should run with Spring to get the injections working

You should also annote the property loginService with @AutoWired and rename the bean in xml to loginService.

Your atrributes and beans names must be the same for Spring bind it for you!

相关问答

更多