0

尝试让基本过滤器与 GPUImage 一起使用,但不确定如何正确设置它以在检测角落时在实时视频源上显示十字准线。我尝试将十字准线与视频一起添加到混合过滤器中,然后将其添加到 gpuimageview 中,但我得到的只是一个白屏。有任何想法吗?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.



    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;


    GPUImageView *filteredVideoView = (GPUImageView *)self.view;


    GPUImageCrosshairGenerator *crosshairGenerator = [[GPUImageCrosshairGenerator alloc] init];
    crosshairGenerator.crosshairWidth = 15.0;
    [crosshairGenerator forceProcessingAtSize:CGSizeMake(480.0, 640.0)];


    customFilter = [[GPUImageHarrisCornerDetectionFilter alloc] init];
    [customFilter setCornersDetectedBlock:^(GLfloat* cornerArray, NSUInteger cornersDetected, CMTime frameTime){
        [crosshairGenerator renderCrosshairsFromArray:cornerArray count:cornersDetected frameTime:frameTime];
        NSLog(@"corners: %u", cornersDetected);
    }];


    GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
    [blendFilter forceProcessingAtSize:CGSizeMake(480.0, 640.0)];

    [videoCamera addTarget:blendFilter];
    [crosshairGenerator addTarget:blendFilter];
    [blendFilter addTarget:filteredVideoView];


    [videoCamera startCameraCapture];

}
4

1 回答 1

0

这就是你的代码在Swift 2.0中的样子

var liveCam:GPUImageVideoCamera!
var edgesDetector:GPUImageHarrisCornerDetectionFilter!
var crosshairGenerator:GPUImageCrosshairGenerator!
@IBOutlet weak var camView: GPUImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    liveCam = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Back)
    liveCam.outputImageOrientation = .Portrait

    crosshairGenerator = GPUImageCrosshairGenerator()
    crosshairGenerator.crosshairWidth = 15
    crosshairGenerator.forceProcessingAtSize(CGSize(width: 480, height: 640))


    edgesDetector = GPUImageHarrisCornerDetectionFilter()
    edgesDetector.blurRadiusInPixels = 2 //Default value
    edgesDetector.threshold = 0.2 //Default value

    edgesDetector.cornersDetectedBlock = {(cornerArray:UnsafeMutablePointer<GLfloat>,cornersDetected:UInt,frameTime:CMTime) -> Void in
        self.crosshairGenerator.renderCrosshairsFromArray(cornerArray, count: cornersDetected, frameTime: frameTime)
        print("\(cornerArray) =-= \(cornersDetected) =-= \(frameTime)")

    }


    liveCam.addTarget(edgesDetector)
    edgesDetector.addTarget(crosshairGenerator)
    crosshairGenerator.addTarget(camView)

    liveCam.startCameraCapture()
}

结果 :

在此处输入图像描述

于 2015-12-09T15:37:40.203 回答