Thank you, that hint helped me to search more efficiently (I am really not into VisualStudio)
Now I found out that low-level-function memcmp tries to access an address that contains nothing.
But what really annoys me is that the algorithm works well if I only run over half the image:
Code:
for (int line = 0; line < imgSize.height/2; line+=4){...}
So I suppose that there is a kind of overflow in the hash_map. Did I do anything wrong with the initialization?
Maybe it is easier to see, if I post the complete code:
Code:
void CCamShiftF::UseH264Q(IplImage* image) {
// -- parameters --------------------------------------
int quantFactor = 1;
short fwdDctBlock[16] =
{
1, 1, 1, 1,
2, 1, -1, -2,
1, -1, -1, 1,
1, -2, 2, -1
};
// ----------------------------------------------------
// -- initialize variables and structures --
unsigned char value8u;
short value16s;
// init sizes
CvSize imgSize; // the size of the given image:
imgSize.height = image->height;
imgSize.width = image->width;
CvSize blockImgSize;
blockImgSize.height = imgSize.height/4;
blockImgSize.width = imgSize.width/4;
// init images:
IplImage* pGrayImage = cvCreateImage(imgSize, IPL_DEPTH_8U, 1);
int stepSize = pGrayImage->widthStep;
IplImage* pBlockImage = cvCreateImage(blockImgSize, IPL_DEPTH_16S, 1);
// init Arrays:
short srcBlock[16] = {0};
short tmpBlock[16] = {0};
short dstBlock[16] = {0};
// init hashtable for the dct blocks
typedef hash_map<string, int> hashtable;
typedef pair<string, int> blockPair;
hashtable blockMap;
hashtable::iterator mapIter;
string blockString = "";
char* tmpStr = new char[5];
int blockIDcounter = 0; // needed for indexing different blocks
int blockID; // the ID of a specific block
// -- apply conversions --
cvCvtPixToPlane(image, pGrayImage, NULL, NULL, NULL); // get first channel only
// -- main application loop --
for (int line = 0; line < imgSize.height; line+=4) {
for (int column = 0; column < imgSize.width; column+=4) {
// fill source Matrix:
for (int mLine = 0; mLine < 4; mLine++) {
for (int mColumn = 0; mColumn < 4; mColumn++) {
value8u = (unsigned char) *(pGrayImage->imageData + (line + mLine)*stepSize + column + mColumn); // get values from grayscale-image
srcBlock[mLine*4 + mColumn] = (short) value8u; // needed because unsigned data is stored in signed char (imageData)
}
} // end of fill source matrix
// -- apply transformation --
// matrix multiplication (FwdDCT * Src = Temp):
for (int mLine = 0; mLine < 4; mLine++) {
for (int mColumn = 0; mColumn < 4; mColumn++) {
value16s = 0;
for (int mElement = 0; mElement < 4; mElement++) {
value16s += fwdDctBlock[mLine*4 + mElement] * srcBlock[mElement*4 + mColumn];
} // end of element-loop
tmpBlock[mLine*4 + mColumn] = value16s;
} // end of column-loop
} // end of matrix multiplication
// matrix multiplication (Temp * FwdDCT' = Dest):
for (int mLine = 0; mLine < 4; mLine++) {
for (int mColumn = 0; mColumn < 4; mColumn++) {
value16s = 0;
for (int mElement = 0; mElement < 4; mElement++) {
value16s += tmpBlock[mLine*4 + mElement] * fwdDctBlock[mColumn*4 + mElement];
} // end of element-loop
//debug// dstBlock[mLine*4 + mColumn] = value16s / 16; // ask Daidi about the / 16
dstBlock[mLine*4 + mColumn] = value16s;
} // end of column-loop
} // end of matrix multiplication
dstBlock[0] = 0; // ignore DC-coefficient
// -- apply quantization --
for (int mLine = 0; mLine < 4; mLine++) {
for (int mColumn = 0; mColumn < 4; mColumn++) {
value16s = dstBlock[mLine*4 + mColumn];
value16s = value16s / quantFactor;
//debug// value16s = value16s * quantFactor;
value16s = value16s * quantFactor / 16;
if (value16s > maxValue)
maxValue = value16s;
else if (value16s < minValue)
minValue = value16s;
}
} // end of quantization
// -- get block ID --
// convert block to blockString:
blockString = "";
for (int element = 0; element < 16; element++) {
if (dstBlock[element] != 0) {
_itoa((int)dstBlock[element], tmpStr, 10);
blockString = blockString += tmpStr;
}
blockString += ":";
}
// add blockString to hashmap
mapIter = blockMap.find(blockString);
if (mapIter == blockMap.end()) {
blockMap.insert(blockPair(blockString, ++blockIDcounter));
blockID = blockIDcounter;
} else {
blockID = mapIter->second;
}
*(pBlockImage->imageData + line*stepSize/4 + column) = blockID; // save blockID to block image
} // end of line
} // end of main application loop
// -- tidy up --
cvReleaseImage(&pBlockImage);
cvReleaseImage(&pGrayImage);
}