#include "opencv2/opencv.hpp" #include #include #include void reMap(cv::Mat src, cv::Mat dst, cv::Mat gray, cv::Mat hist) { for (int i = 0; i < src.rows * src.cols; i++) { if (gray.data[i] == 0) { dst.data[i * 3] = 0; dst.data[i * 3 + 1] = 0; dst.data[i * 3 + 2] = 0; } else { dst.data[i * 3] = src.data[i * 3] * hist.data[i] / gray.data[i]; dst.data[i * 3 + 1] = src.data[i * 3 + 1] * hist.data[i] / gray.data[i]; dst.data[i * 3 + 2] = src.data[i * 3 + 2] * hist.data[i] / gray.data[i]; } } } int main() { cv::VideoCapture cap; cap.open("/home/zara/让子弹飞.flv"); cv::VideoWriter writer("app0.mp4", cv::VideoWriter::fourcc('m', 'p', '4', 'v'), 30, cv::Size(int(cap.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_WIDTH)), int(cap.get(cv::VideoCaptureProperties::CAP_PROP_FRAME_HEIGHT)))); cv::Mat image; cv::Mat gray; cv::Mat hist; cv::Mat dst(int(cap.get(4)),int(cap.get(3)),CV_8UC3); dst.data = (unsigned char *)malloc(int(cap.get(3) * cap.get(4)) * 3); while (cap.read(image)) { cv::cvtColor(image, gray, cv::COLOR_RGB2GRAY); cv::equalizeHist(gray, hist); reMap(image, dst, gray, hist); cv::imshow("default",dst); writer.write(dst); if (cv::waitKey(2) == 'q') { break; } } writer.release(); cap.release(); image.release(); }