J'ai une fuite dans le code que j'ai mis ci-dessous. Quand j'ai utilisé cvCreateImage au lieu de cvCreateImageHeader, il y avait une fuite de 304Kb et 107b mais quand j'ai changé, il est devenu 107 bits seulement. Pourriez-vous m'aider à trouver une fuite?Fuite dans OpenCV NSImage Vers la procédure du convertisseur 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;
}
La question semble foiré .. pourriez-vous le formater un peu mieux? –