…
#import <opencv2/opencv.hpp>
…
@implementation OpenCV_XXXPlugIn
…
@dynamic inputSourceImage;
@dynamic outputResultImage;
…
@end
@implementation OpenCV_XXXPlugIn (Execution)
…
static void _BufferReleaseCallback(const void* address, void* info)
{
}
+(cv::Mat)CVMatWithQCPlugInInputImageSource:(id <QCPlugInInputImageSource>)image
{
CGFloat cols = [image bufferPixelsWide];
CGFloat rows = [image bufferPixelsHigh];
cv::Mat cvMat(rows, cols, CV_8UC4);
cvMat.data= (uchar *)[image bufferBaseAddress];
return cvMat;
}
- (BOOL)execute:(id <QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary *)arguments
{
id inputImage= self.inputSourceImage;
self.outputResultImage = nil;
if(inputImage) {
if(![inputImage lockBufferRepresentationWithPixelFormat:QCPlugInPixelFormatBGRA8
colorSpace:[inputImage imageColorSpace]
forBounds:[inputImage imageBounds]]) {
return NO;
}
cv::Mat src_img= [OpenCV_XXXPlugIn CVMatWithQCPlugInInputImageSource:inputImage];
cv::Mat dst_img(src_img.size(), src_img.type());
src_img.copyTo(dst_img);
id <QCPlugInOutputImageProvider> provider= [context outputImageProviderFromBufferWithPixelFormat:QCPlugInPixelFormatBGRA8
pixelsWide:dst_img.cols
pixelsHigh:dst_img.rows
baseAddress:dst_img.data
bytesPerRow:dst_img.cols*dst_img.channels()
releaseCallback:_BufferReleaseCallback
releaseContext:NULL
colorSpace:[inputImage imageColorSpace]
shouldColorMatch:YES];
if(provider == nil)
return NO;
self.outputResultImage = provider;
[inputImage unlockBufferRepresentation];
}
return YES;
}
…
@end
0 件のコメント:
コメントを投稿