아래 코드에 누수가 있습니다. cvCreateImageHeader 대신 cvCreateImage를 사용했을 때 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;
}
질문이 엉망으로 보입니다. 좀 더 형식화 할 수 있었습니까? –