创建按钮,总是报错,一开始是报错缺少QT支持,后来创建QT Application程序编译不报错,运行时会 下面是单独实现绘制直方图代码,解决上面方法的方案,求大神知道 #include "testqt_1101.h" #include <QtWidgets/QApplication> #include <opencv2\core\utility.hpp> #include <opencv2\imgproc.hpp> #include <opencv2\highgui.hpp> #include <iostream> using namespace std; using namespace cv; Mat img= imread("C:\\Users\\hasee\\Desktop\\cat2.jpg"); void showHistoCallback(int state, void* userData); void equlizeCallback(int state, void* userData); int main() { vector<Mat> bgr; split(img, bgr); int numbins = 256; float range[] = { 0,256 }; const float* histRange = { range }; Mat b_hist, g_hist, r_hist; calcHist(&bgr[0], 1, 0, Mat(), b_hist, 1, &numbins, &histRange); calcHist(&bgr[1], 1, 0, Mat(), g_hist, 1, &numbins, &histRange); calcHist(&bgr[2], 1, 0, Mat(), r_hist, 1, &numbins, &histRange); int width = 512; int height = 300; Mat histImage(height, width, CV_8UC3, Scalar(20, 20, 20)); normalize(b_hist, b_hist, 0, height, NORM_MINMAX); normalize(g_hist, g_hist, 0, height, NORM_MINMAX); normalize(r_hist, r_hist, 0, height, NORM_MINMAX); int binStep = cvRound((float)width / (float)numbins); for (int i = 1; i < numbins; i++) { line(histImage, Point(binStep*(i - 1), height - cvRound(b_hist.at<float>(i - 1))), Point(binStep*(i), height - cvRound(b_hist.at<float>(i))), Scalar(255, 0, 0)); line(histImage, Point(binStep*(i - 1), height - cvRound(g_hist.at<float>(i - 1))), Point(binStep*(i), height - cvRound(g_hist.at<float>(i))), Scalar(0, 255, 0)); line(histImage, Point(binStep*(i - 1), height - cvRound(r_hist.at<float>(i - 1))), Point(binStep*(i), height - cvRound(r_hist.at<float>(i))), Scalar(0, 0, 255)); } imshow("直方图", histImage); //namedWindow("Input"); //createButton("ss", showHistoCallback, NULL, QT_PUSH_BUTTON, 0); //createButton("直方图均衡化",equlizeCallback,NULL,QT_PUSH_BUTTON,0); //imshow("Input", img);*/ waitKey(0); return 0; }