我正在从分辨率为 102 x 77 的成像器中捕获一帧数据。我想将其降低到 80 x 60。质量不是主要问题,但易于实施和速度才是。
我相信我可以通过大约每 4 个像素下降一次来实现这一点:
>>> 80.0 / 102.0
0.7843137254901961
>>>
>>> 60.0 / 77.0
0.7792207792207793
>>>
>>> 102 * ( 0.75 )
76.5
>>> 77 * ( 0.75 )
57.75
既然不完全是 4,我该如何解释呢?减少获得 80 x 60 所需的像素数的最佳方法是什么?谢谢。
我迭代像素的代码:
// Initialize data store for frame pixel data
vector<quint8> data;
data.resize(frame.getHeight() * frame.getWidth());
// Try to get a frame
forever
{
// Request a frame and check return status
if ( !getRawFrame(frame) ) {
qDebug() << "************************";
qDebug() << "Failed Capture Attempt!";
qDebug() << "************************";
// Failed - try again
continue;
}
// Get the height and width
int h = frame.getHeight();
int w = frame.getWidth();
// Get the frame raw data
vector<quint8> rawdata = frame.getRawData();
// Iterate the pixels
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
// Extract
quint8 pixelValue = reinterpret_cast<quint8*>(rawdata.data())[y*w+x];
int convertToInt = int(pixelValue);
/// do stuff on pixel data
// Downconvert
pixelValue = convertToInt;
// Assign
data[y*w+x] = pixelValue;
}
}
// Assign the data to the Frame now
frame.setData(data);
// Done with capture loop
break;
}