C++错误:对"(RgbImage) (int&, int&)"的调用不匹配
C++ error: no match for call to ‘(RgbImage) (int&, int&)’
我试图为这个实现遵循的伪代码:
for (int u = 0; u < uMax; u++)
{ for (int v = 0; v < vMax; v++)
{ float x = f_x(u, v);
float y = f_y(u, v);
dstImage(x, y) = srcImage(u, v);
}
}
我试图用缩放函数来实现上面的代码。我对每个像素进行迭代,就像我改变r、g、b一样,但我在改变x的值时遇到了问题。我已经实现了更改图像的r、g和b的代码,但我现在希望能够将图像的x缩放2倍。这是以与改变r、g、b相同的方式缩放x的尝试。
void scale()
{
RgbImage theTexMap( filename ); // loaded from some file name
//RgbImage destination;
double r, g, b; // variables to store the different colours
float u, v;
for (int x = 0; x < theTexMap.GetNumRows(); x++)
{ for (int y = 0; y < theTexMap.GetNumCols(); y++)
{ theTexMap.GetRgbPixel(x, y, &r, &g, &b); //this successfully allows me to change the r,g,b values
u = x * 2;
v = y;
//cout << x <<endl;
//cout << y << " " << endl;
//cout << " " <<endl;
destination.SetRgbPixelf(u, v, r, g, b); //allows me to set r,g,b values, fails with the x,y.
}
}
updateTexture(&destination, modifiedID);
}
根据我试图遵循的伪代码,它应该更像这样。(在for循环内部更改,并使用u,v迭代)
void scale()
{
RgbImage theTexMap( filename ); // loaded from some file name
//RgbImage destination;
double r, g, b; // variables to store the different colours
float x, y;
for (int u = 0; u < theTexMap.GetNumRows(); u++)
{ for (int v = 0; v < theTexMap.GetNumCols(); v++)
{ x = u * 2;
y = v;
//cout << x <<endl;
//cout << y << " " << endl;
//cout << " " <<endl;
theTexMap(x,y) = theTexMap(u,v)
}
}
updateTexture(&theTexMap, modifiedID);
}
现在,因为我并不真正理解最后一行的伪代码,所以当我在实现中调用它时,我会收到这个错误消息。我收到的错误消息。
error: no match for call to ‘(RgbImage) (float&, float&)’
theTexMap(x,y) = theTexMap(u,v);
好吧,现在你说,我不知道RgbImage(TexMap的类型)是什么,你这个傻瓜。这是课堂。我应该像上面那样在这种情况下使用它吗?或者我应该如何遵循伪代码来获得我想要的2缩放因子?
#include "RgbImage.h"
#ifndef RGBIMAGE_DONT_USE_OPENGL
#ifdef _WIN32
#include <windows.h>
#endif
#include "GL/gl.h"
#endif
RgbImage::RgbImage( int numRows, int numCols )
{
NumRows = numRows;
NumCols = numCols;
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld bitmap.n",
NumRows, NumCols);
Reset();
ErrorCode = MemoryError;
}
// Zero out the image
unsigned char* c = ImagePtr;
int rowLen = GetNumBytesPerRow();
for ( int i=0; i<NumRows; i++ ) {
for ( int j=0; j<rowLen; j++ ) {
*(c++) = 0;
}
}
}
bool RgbImage::LoadBmpFile( const char* filename )
{
Reset();
FILE* infile = fopen( filename, "rb" ); // Open for reading binary data
if ( !infile ) {
fprintf(stderr, "Unable to open file: %sn", filename);
ErrorCode = OpenError;
return false;
}
bool fileFormatOK = false;
int bChar = fgetc( infile );
int mChar = fgetc( infile );
if ( bChar=='B' && mChar=='M' ) { // If starts with "BM" for "BitMap"
skipChars( infile, 4+2+2+4+4 ); // Skip 4 fields we don't care about
NumCols = readLong( infile );
NumRows = readLong( infile );
skipChars( infile, 2 ); // Skip one field
int bitsPerPixel = readShort( infile );
skipChars( infile, 4+4+4+4+4+4 ); // Skip 6 more fields
if ( NumCols>0 && NumCols<=100000 && NumRows>0 && NumRows<=100000
&& bitsPerPixel==24 && !feof(infile) ) {
fileFormatOK = true;
}
}
if ( !fileFormatOK ) {
Reset();
ErrorCode = FileFormatError;
fprintf(stderr, "Not a valid 24-bit bitmap file: %s.n", filename);
fclose ( infile );
return false;
}
// Allocate memory
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld bitmap: %s.n",
NumRows, NumCols, filename);
Reset();
ErrorCode = MemoryError;
fclose ( infile );
return false;
}
unsigned char* cPtr = ImagePtr;
for ( int i=0; i<NumRows; i++ ) {
int j;
for ( j=0; j<NumCols; j++ ) {
*(cPtr+2) = fgetc( infile ); // Blue color value
*(cPtr+1) = fgetc( infile ); // Green color value
*cPtr = fgetc( infile ); // Red color value
cPtr += 3;
}
int k=3*NumCols; // Num bytes already read
for ( ; k<GetNumBytesPerRow(); k++ ) {
fgetc( infile ); // Read and ignore padding;
*(cPtr++) = 0;
}
}
if ( feof( infile ) ) {
fprintf( stderr, "Premature end of file: %s.n", filename );
Reset();
ErrorCode = ReadError;
fclose ( infile );
return false;
}
fclose( infile ); // Close the file
return true;
}
short RgbImage::readShort( FILE* infile )
{
// read a 16 bit integer
unsigned char lowByte, hiByte;
lowByte = fgetc(infile); // Read the low order byte (little endian form)
hiByte = fgetc(infile); // Read the high order byte
// Pack together
short ret = hiByte;
ret <<= 8;
ret |= lowByte;
return ret;
}
long RgbImage::readLong( FILE* infile )
{
// Read in 32 bit integer
unsigned char byte0, byte1, byte2, byte3;
byte0 = fgetc(infile); // Read bytes, low order to high order
byte1 = fgetc(infile);
byte2 = fgetc(infile);
byte3 = fgetc(infile);
// Pack together
long ret = byte3;
ret <<= 8;
ret |= byte2;
ret <<= 8;
ret |= byte1;
ret <<= 8;
ret |= byte0;
return ret;
}
void RgbImage::skipChars( FILE* infile, int numChars )
{
for ( int i=0; i<numChars; i++ ) {
fgetc( infile );
}
}
bool RgbImage::WriteBmpFile( const char* filename )
{
FILE* outfile = fopen( filename, "wb" ); // Open for reading binary data
if ( !outfile ) {
fprintf(stderr, "Unable to open file: %sn", filename);
ErrorCode = OpenError;
return false;
}
fputc('B',outfile);
fputc('M',outfile);
int rowLen = GetNumBytesPerRow();
writeLong( 40+14+NumRows*rowLen, outfile ); // Length of file
writeShort( 0, outfile ); // Reserved for future use
writeShort( 0, outfile );
writeLong( 40+14, outfile ); // Offset to pixel data
writeLong( 40, outfile ); // header length
writeLong( NumCols, outfile ); // width in pixels
writeLong( NumRows, outfile ); // height in pixels (pos for bottom up)
writeShort( 1, outfile ); // number of planes
writeShort( 24, outfile ); // bits per pixel
writeLong( 0, outfile ); // no compression
writeLong( 0, outfile ); // not used if no compression
writeLong( 0, outfile ); // Pixels per meter
writeLong( 0, outfile ); // Pixels per meter
writeLong( 0, outfile ); // unused for 24 bits/pixel
writeLong( 0, outfile ); // unused for 24 bits/pixel
// Now write out the pixel data:
unsigned char* cPtr = ImagePtr;
for ( int i=0; i<NumRows; i++ ) {
// Write out i-th row's data
int j;
for ( j=0; j<NumCols; j++ ) {
fputc( *(cPtr+2), outfile); // Blue color value
fputc( *(cPtr+1), outfile); // Blue color value
fputc( *(cPtr+0), outfile); // Blue color value
cPtr+=3;
}
// Pad row to word boundary
int k=3*NumCols; // Num bytes already read
for ( ; k<GetNumBytesPerRow(); k++ ) {
fputc( 0, outfile ); // Read and ignore padding;
cPtr++;
}
}
fclose( outfile ); // Close the file
return true;
}
void RgbImage::writeLong( long data, FILE* outfile )
{
// Read in 32 bit integer
unsigned char byte0, byte1, byte2, byte3;
byte0 = (unsigned char)(data&0x000000ff); // Write bytes, low order to high order
byte1 = (unsigned char)((data>>8)&0x000000ff);
byte2 = (unsigned char)((data>>16)&0x000000ff);
byte3 = (unsigned char)((data>>24)&0x000000ff);
fputc( byte0, outfile );
fputc( byte1, outfile );
fputc( byte2, outfile );
fputc( byte3, outfile );
}
void RgbImage::writeShort( short data, FILE* outfile )
{
// Read in 32 bit integer
unsigned char byte0, byte1;
byte0 = data&0x000000ff; // Write bytes, low order to high order
byte1 = (data>>8)&0x000000ff;
fputc( byte0, outfile );
fputc( byte1, outfile );
}
/*********************************************************************
* SetRgbPixel routines allow changing the contents of the RgbImage. *
*********************************************************************/
void RgbImage::SetRgbPixelf( long row, long col, double red, double green, double blue )
{
SetRgbPixelc( row, col, doubleToUnsignedChar(red),
doubleToUnsignedChar(green),
doubleToUnsignedChar(blue) );
}
void RgbImage::SetRgbPixelc( long row, long col,
unsigned char red, unsigned char green, unsigned char blue )
{
assert ( row<NumRows && col<NumCols );
unsigned char* thePixel = GetRgbPixel( row, col );
*(thePixel++) = red;
*(thePixel++) = green;
*(thePixel) = blue;
}
unsigned char RgbImage::doubleToUnsignedChar( double x )
{
if ( x>=1.0 ) {
return (unsigned char)255;
}
else if ( x<=0.0 ) {
return (unsigned char)0;
}
else {
return (unsigned char)(x*255.0); // Rounds down
}
}
// Bitmap file format (24 bit/pixel form) BITMAPFILEHEADER
// Header (14 bytes)
// 2 bytes: "BM"
// 4 bytes: long int, file size
// 4 bytes: reserved (actually 2 bytes twice)
// 4 bytes: long int, offset to raster data
// Info header (40 bytes) BITMAPINFOHEADER
// 4 bytes: long int, size of info header (=40)
// 4 bytes: long int, bitmap width in pixels
// 4 bytes: long int, bitmap height in pixels
// 2 bytes: short int, number of planes (=1)
// 2 bytes: short int, bits per pixel
// 4 bytes: long int, type of compression (not applicable to 24 bits/pixel)
// 4 bytes: long int, image size (not used unless compression is used)
// 4 bytes: long int, x pixels per meter
// 4 bytes: long int, y pixels per meter
// 4 bytes: colors used (not applicable to 24 bit color)
// 4 bytes: colors important (not applicable to 24 bit color)
// "long int" really means "unsigned long int"
// Pixel data: 3 bytes per pixel: RGB values (in reverse order).
// Rows padded to multiples of four.
#ifndef RGBIMAGE_DONT_USE_OPENGL
bool RgbImage::LoadFromOpenglBuffer() // Load the bitmap from the current OpenGL buffer
{
int viewportData[4];
glGetIntegerv( GL_VIEWPORT, viewportData );
int& vWidth = viewportData[2];
int& vHeight = viewportData[3];
if ( ImagePtr==0 ) { // If no memory allocated
NumRows = vHeight;
NumCols = vWidth;
ImagePtr = new unsigned char[NumRows*GetNumBytesPerRow()];
if ( !ImagePtr ) {
fprintf(stderr, "Unable to allocate memory for %ld x %ld buffer.n",
NumRows, NumCols);
Reset();
ErrorCode = MemoryError;
return false;
}
}
assert ( vWidth>=NumCols && vHeight>=NumRows );
int oldGlRowLen;
if ( vWidth>=NumCols ) {
glGetIntegerv( GL_UNPACK_ROW_LENGTH, &oldGlRowLen );
glPixelStorei( GL_UNPACK_ROW_LENGTH, NumCols );
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
// Get the frame buffer data.
glReadPixels( 0, 0, NumCols, NumRows, GL_RGB, GL_UNSIGNED_BYTE, ImagePtr);
// Restore the row length in glPixelStorei (really ought to restore alignment too).
if ( vWidth>=NumCols ) {
glPixelStorei( GL_UNPACK_ROW_LENGTH, oldGlRowLen );
}
return true;
}
#endif // RGBIMAGE_DONT_USE_OPENGL
此表达式:
theTexMap(x,y) = theTexMap(u,v);
^^^^^^^^^^^^^^
正在尝试调用RgbImage::operator()(float, float)
。这不是您的类型上定义的运算符,因此会出现错误。
我猜你想调用的函数是:
theTexMap.GetRgbPixel(u, v, &r, &g, &b);
theTexMap.SetRgbPixelf(x, y, r, g, b);
相关文章:
- 调用'begin(int [n])'没有匹配函数
- Qt SQLite没有查询或参数计数不匹配
- 错误:运算符 [] 不匹配。在比较列表中的 int 和 int 时<int>,
- 与"运算符[]"不匹配(操作数类型为"std::unique_ptr<std::vector<int> >"和"int")
- 错误:与'operator='不匹配(操作数类型为"std::map<int、double>::iterator
- 错误:与"运算符[]"不匹配(操作数类型为"QVector<int>"和"QCharRef")
- 有没有办法修复此错误:与'operator[]'不匹配(操作数类型为 'empl' 和"int")
- C++错误:与调用'(std::list<int>) (int&)'不匹配
- 对"(std::vector<std::vector<int> >) (int, std::vector<int>)"的调用不匹配
- 希望修复 main.cpp 与"std::istream&<< int&"运算符不匹配
- 与"运算符[]"不匹配(操作数类型为"Briques"和"int")
- C++:尝试遍历 boost::unordered_map<string,int> 时,运算符不匹配<
- OpenCV:错误:与调用'(cv::Mat) (int&, int&)'不匹配
- Visual Studio调试与发布版本:比较int和float不匹配
- C++错误:对"(RgbImage) (int&, int&)"的调用不匹配
- 有符号/无符号 int 不匹配
- 错误:对'(Time) (int, int, int)'的调用不匹配
- [C++ STL]-pair<vector-iter,int*> - 不匹配 - 无匹配函数
- 错误消息:与调用"(cv::Rect) (cv::Mat&, cv::P oint_, cv:<int>:P oint, cv::Scalar, int)"的调用不匹配
- map<int、int>::iterator 的编译错误,运算符 = 不匹配