Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by 叶林 on 2018/5/1.
- //
- #include "HistogramHelper.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- HistogramHelper::HistogramHelper(){
- hisSize = 128;
- //Match MATLAB imhist
- float bin_width = (255.0 - 0.0) / (128 - 1);
- float bin_width_half = bin_width / 2;
- ranges_ptr[0] = 0;
- ranges_ptr[1] = bin_width_half;
- ranges_ptr[128] = 255.0;
- for (int i = 2; i < 128; i++)
- {
- ranges_ptr[i] = ranges_ptr[i - 1] + bin_width;
- }
- ranges = ranges_ptr;
- }
- void HistogramHelper::importImage(Mat& curFrame){
- image = curFrame;
- }
- Mat HistogramHelper::getHistogram(){
- // Mat tmp;
- // cv::cvtColor(image, tmp, cv::COLOR_BGR2YCrCb);
- // for(int i = 0; i < tmp.rows; i++){
- // for(int j =0; j < tmp.cols; j++){
- // cout<< tmp.at<float>(i, j)<<endl;
- // }
- // }
- split(image, channelsRGB);
- Mat result;
- calcHist(&channelsRGB[0],1,0,Mat(),outputRGB[0], 1, &hisSize, &ranges, false);
- calcHist(&channelsRGB[1],1,0,Mat(),outputRGB[1], 1, &hisSize, &ranges, false);
- calcHist(&channelsRGB[2],1,0,Mat(),outputRGB[2], 1, &hisSize, &ranges, false);
- ofstream in;
- in.open("data2.txt", ios::trunc);
- for (int j = 0; j < outputRGB[2].rows; j++){
- in << outputRGB[2].at<float>(j) << "\n";
- }
- in.close();
- result.create(outputRGB[0].rows, 3, outputRGB->type());
- for (int i = 0; i < 3; ++i) {
- for (int j = 0; j < outputRGB[i].rows; ++j) {
- result.at<float>(j, i) = outputRGB[i].at<float>(j, 0);
- }
- }
- return result;
- }
Add Comment
Please, Sign In to add comment