Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/opencv.hpp>
- #include <math.h>
- #include <time.h>
- #include <iostream>
- #include <iomanip>
- #include <vector>
- using namespace cv;
- int main() {
- Mat img = imread("data_cross_0256x0256.png");
- if (img.empty()) {
- std::cout << "Can not open or image is not present" << std::endl;
- return 0;
- }
- Mat img_chromo;
- cvtColor(img, img_chromo, COLOR_BGR2GRAY);
- Mat result(256, 512, CV_8U, 255);
- std::vector<int> v(256);
- for (int i = 0; i < img_chromo.cols; ++i) {
- for (int j = 0; j < img_chromo.rows; ++j) {
- uchar cur_color = img_chromo.at<uchar>(j, i);
- v[cur_color]++;
- }
- }
- int max_count = *max_element(v.begin(), v.end());
- for (int i = 0; i < 256; ++i) {
- int h = v[i] * 250 / max_count;
- Point pt1(i * 2, 255 - h);
- Point pt2(i * 2 + 1,255);
- rectangle(result, pt1, pt2, 0);
- }
- imshow("result", result);
- imshow("cat", img);
- imshow("cat2", img_chromo);
- waitKey(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement