看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) win7 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) opencv 問題(Question): 在使用calcHist做直方圖的計算時以整張圖來做計算及畫圖是OK的 但想要更精確表示圖像的話必須將圖塊切塊後(EX:3*3)再將各區塊的直方圖連接起來 做為整張圖的特徵直方圖 我用了阿洲的程式教學裡的方式做運算 但只能做單一整張的直方圖 不知有無方式可以繪製出連接後的直方圖呢 謝謝大家 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) #include <cstdio> #include <opencv2/opencv.hpp> using namespace cv; void drawHistImg(const Mat &src, Mat &dst); int main(){ Mat src = imread("lena.jpg",CV_LOAD_IMAGE_GRAYSCALE); int histSize = 256; float range[] = {0, 255} ; const float* histRange = {range}; Mat histImg; calcHist(&src, 1, 0, Mat(), histImg, 1, &histSize, &histRange); Mat showHistImg(256,256,CV_8UC1,Scalar(255)); //把直方圖秀在一個256*256大 的影像上 drawHistImg(histImg, showHistImg); imshow("window1", src); imshow("window2", showHistImg); waitKey(0); return 0; } void drawHistImg(const Mat &src, Mat &dst){ int histSize = 256; float histMaxValue = 0; for(int i=0; i<histSize; i++){ float tempValue = src.at<float>(i); if(histMaxValue < tempValue){ histMaxValue = tempValue; } } float scale = (0.9*256)/histMaxValue; for(int i=0; i<histSize; i++){ int intensity = static_cast<int>(src.at<float>(i)*scale); line(dst,Point(i,255),Point(i,255-intensity),Scalar(0)); } } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.116.40.159 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1501145128.A.545.html
longlongint: 直接畫整張直方圖? 07/28 21:57
longlongint: 請問連接是什麼意思 07/28 21:58
LGham: 比如說把整張圖切成9塊 個別計算直方圖 再將九個直方圖連 07/29 09:44
LGham: 接起來 07/29 09:44
waterCoka: 請搜尋local histogram equalization 07/29 13:10
longlongint: 直方圖是256根棒子 連起來要做什麼 變成更多棒子? 07/30 14:10
LGham: 分區塊再連接起來這樣特徵會比較明顯 07/30 15:49
Raymond0710: 用pushback 07/31 06:52