verticalaverage.cpp
来自「barcode readers [ from Image]」· C++ 代码 · 共 73 行
CPP
73 行
//
// VerticalAverage
// Returns a 1-dimensional array that is the average value in
// each column of the image.
//
// Copyright (C) 2003, 2006 by Jon A. Webb (Contact via GMail; username is jonawebb)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
#include "VerticalAverage.h"
#include "Debug.h"
#include "GrayImageIter.h"
#include "Image.h"
#include "ImageSize.h"
#include <e32std.h>
#include <fbs.h>
using namespace Core;
namespace Algorithm
{
EXPORT_C CVerticalAverage* CVerticalAverage::NewL()
{
return new (ELeave) CVerticalAverage();
}
CVerticalAverage::~CVerticalAverage()
{
}
CVerticalAverage::CVerticalAverage()
{
}
void CVerticalAverage::DoItL(CImage image, CArray<unsigned char>*& average)
{
IImageSize size(image);
CArray<int>* pSum = CArray<int>::NewL(size.Width());
CleanupStack::PushL(pSum);
Mem::FillZ((TAny*)&(*pSum)[0], size.Width() * sizeof(int));
image.LockLC();
IGrayImageIter it(image);
int i;
for (; !it.End(); it.NextRow()) {
for (i=0; !it.REnd(); it++, i++) {
(*pSum)[i] += it();
}
}
CleanupStack::PopAndDestroy(); // unlock
average = CArray<unsigned char>::NewL(size.Width());
for (i=0; i<size.Width(); i++) {
(*average)[i] = (unsigned char) ((*pSum)[i] / size.Height());
}
CleanupStack::PopAndDestroy(pSum);
}
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?