OpenCV:绘制图像的BGR三通道直方图

本文介绍了如何利用OpenCV库在Python中分别绘制BGR三通道的图像直方图。通过这一过程,读者可以理解每个通道颜色在图像中的分布情况。
摘要由CSDN通过智能技术生成
<span style="font-size:14px;">#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv\cxcore.h>

IplImage* DrawHistogram(CvHistogram* hist, float scaleX = 1, float scaleY = 1){

    float histMax = 0;
    cvGetMinMaxHistValue(hist, 0, &histMax, 0, 0); //获取直方图的最大值

    IplImage* imageHist = cvCreateImage(cvSize(256*scaleX, 64*scaleY), 8, 1);
    cvZero(imageHist);

    for(int i = 0; i < 255; ++i){

        //查询直方图每个单位的x值对应的y值
        float histValue = cvQueryHistValue_1D(hist, i);
        float nextValue = cvQueryHistValue_1D(hist, i+1);

        CvPoint pt1 = cvPoint(i* scaleX, 64*scaleY);
        CvPoint pt2 = cvPoint((i+1)*scaleX, 64*scaleY);
        CvPoint pt3 = cvPoint((i+1)*scaleX, 64*scaleY - (nextValue/histMax)*64*scaleY);
        CvPoint pt4 = cvPoint(i*scaleX, 64*scaleY - (histValue/histMax)*64*scaleY);

        int numPts 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值