• opencv中遍历图片数据的两种方法


    方法一:

    IplImage *pImg = ...;

    int nWidth = pImg->width;

    int nHeight = pImg->height;

    int nChannels = pImg->nChannels;

    int nStep = pImg->widthStep;

    for (int i=0; i<nHeight; i++)

    for(int j=0; j<nWidth; j++)

    for (int k=0; k<nChannels; k++)

    {

    pImg->imageData[i*nStep + j*nChannels + k] = 255 - pImg->imageData[i*nStep + j*nChannels + k];

    }

    方法二:

    IplImage *image = ...;

    int div = 8;

    int nl = image->height;

    int nc = image->width*image->nChannels;

    int step = image->widthStep;

    unsigned char *data = (unsigned char *)image->imageData;

    for (int i=1; i<nl; i++)

    {

    for (int j=0; j<nc; j+=image->nChannels)

    {

    data[j] += div/2;

    data[j+1] += div/2;

    data[j+2] += div/2;

    }

    data += step;

    }

  • 相关阅读:
    阅读笔记
    学习小记
    networkx学习笔记
    ORM查询简化
    redis等缓存
    redis相关缓存知识
    Centos7网络配置
    redis安装详细
    redis安装详细
    mobaxterm使用手册
  • 原文地址:https://www.cnblogs.com/mfryf/p/2361791.html
Copyright © 2020-2023  润新知