2
我在下面的代码泄漏。当我使用cvCreateImage而不是cvCreateImageHeader时,它是304Kb和107b泄漏,但是当我改变它时,它变成只有107个叮咬。 你能帮我找到泄漏吗?在OpenCV NSImage泄漏到IplImage转换器程序
+ (IplImage *) nsImageToIplImage:(NSImage *)image {
// NSImage to IplImage
NSBitmapImageRep *orig = [[image representations] objectAtIndex: 0];
// a copy or else the color-channel shift that we do later on will affect the original NSImage!
NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:[orig representationUsingType:NSTIFFFileType properties:NULL]];
int depth = [rep bitsPerSample];
int channels = [rep samplesPerPixel];
int height = [rep size].height;
int width = [rep size].width;
// note- channels had better be "3", or else the loop down below will act pretty funky...
// NSTIFFFileType seems to always give three-channel images, so I think it's okay...
IplImage *to_return = cvCreateImageHeader(cvSize(width, height), depth, channels);
cvSetImageData(to_return, [rep bitmapData], [rep bytesPerRow]);
// Reorder BGR to RGB
// no, I don't know why it's in BGR after cvSetData
for (int i = 0; i < to_return->imageSize; i += 3) {
uchar tempR, tempG, tempB;
tempR = to_return->imageData[i];
tempG = to_return->imageData[i+1];
tempB = to_return->imageData[i+2];
to_return->imageData[i] = tempR;
to_return->imageData[i+1] =tempG;
to_return->imageData[i+2] = tempB;
}
return to_return;
}
这个问题似乎搞砸了..你能格式化它好一点吗? – 2010-07-22 16:55:13