更新:我最后更新我的代码。

似乎我对this site有相同的问题,但情况不同。所以我尝试在viewController.swift中使用来自GPUImage2框架的shiTomasiFeatureDetector过滤器,并且在行camera --> blendFilter --> renderView中获得了代码= 1 / code = 2的EXC_BAD_ACCESS。这是我的代码:

import UIKit
import CoreImage
import GPUImage
import AVFoundation
import QuartzCore

class ViewController: UIViewController {

    @IBOutlet var filterView: RenderView?
    var videoCamera: Camera?

    required init(coder aDecoder: NSCoder) {
        do {
            videoCamera = try Camera(sessionPreset: AVCaptureSessionPreset640x480, location: .backFacing)
            videoCamera!.runBenchmark = true
        } catch {
            videoCamera = nil
            print("Couldn't initialize camera with error: \(error)")
        }
        super.init(coder: aDecoder)!
    }

    // declare filters and crosshairs
    var shiTomasiFilter = ShiTomasiFeatureDetector()
    lazy var crosshairGenerator: CrosshairGenerator = {
        let generator = CrosshairGenerator(size:Size(width:480, height:640))
        generator.crosshairWidth = 15.0
        return generator
    }()
    let blendFilter = AlphaBlend()


    override func viewDidLoad() {
        super.viewDidLoad()

        //  re-declare camera using guard-statement
        guard let videoCamera = videoCamera else {
            let errorAlertController = UIAlertController(title: NSLocalizedString("Error", comment: "Error"), message: "Couldn't initialize camera", preferredStyle: .alert)
            errorAlertController.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "OK"), style: .default, handler: nil))
            self.present(errorAlertController, animated: true, completion: nil)
            return
        }

        if let view = self.filterView {
            //  gettin' corners
            shiTomasiFilter.cornersDetectedCallback = {
                corners in self.crosshairGenerator.renderCrosshairs(corners)
            }
            shiTomasiFilter.threshold = 0.1

            videoCamera --> shiTomasiFilter
            crosshairGenerator --> blendFilter

            videoCamera --> blendFilter --> view

            videoCamera.startCapture()
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}


我有什么建议吗?

错误链接:
error link

在Pipeline.swift中链接的错误

最佳答案

我得到了答案!
您所要做的就是检查左侧的身份检查器(实用工具栏),检查类和模块是否使用“ RenderView”类和GPUImage模块。

10-08 06:08