イメージャーから 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;
}