首页 > Uncategorized > openCV生成灰度图像示例

openCV生成灰度图像示例

临时用到,对openCV还不熟,慢慢研究。

#include "cxcore.h"

IplImage* pImg = cvCreateImage( cvSize( width, height ), 8, 1 );

cvZero( pImg );

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

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

    {

        CvPoint pt = cvPoint(i, j);

        uchar* temp = &((uchar*)(pImg->imageDate /* +distance */))[pt.x];

        temp[0] = static_cast<int>( value(0~255) );

    }

cvSaveImage( filename, pImg);

cvReleaseImage(&pImg);

分类: Uncategorized 标签:,
  1. gbai
    04月 16, 2010 @ 4:04 pm | #1

    If you take width as the inner loop and height as the outer, the code will be much more effective. Because of the layout of CvArr, it is cache-friendly to do so.

  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s

加关注

Get every new post delivered to your Inbox.