GPUImage覆盖带角点检测的实时视频

时间:2013-01-28 17:38:24

标签: iphone ios gpuimage

尝试使用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];

}

1 个答案:

答案 0 :(得分: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()
}

结果:

enter image description here