EXC_BAD_ACCESS 在 GPUImage2 中尝试 shiTomasiFeatureDetector 过滤器时
EXC_BAD_ACCESS when try shiTomasiFeatureDetector filter in GPUImage2
更新:我最后更新了我的代码。
似乎我和 this site 有同样的问题,但情况不同。因此,我尝试在 viewController.swift 中使用 GPUImage2 框架中的 shiTomasiFeatureDetector 过滤器,并且在行 camera --> blendFilter --> renderView
中得到了 EXC_BAD_ACCESS 和 code=1/code=2。这是我的代码:
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.
}
}
我有什么建议吗?
错误link:
error link
错误 link 编辑在 Pipeline.swift
我得到答案了!
您所要做的就是检查左侧的身份检查器(实用程序栏),检查 class 和模块是否使用 'RenderView' class 和 GPUImage 模块。
更新:我最后更新了我的代码。
似乎我和 this site 有同样的问题,但情况不同。因此,我尝试在 viewController.swift 中使用 GPUImage2 框架中的 shiTomasiFeatureDetector 过滤器,并且在行 camera --> blendFilter --> renderView
中得到了 EXC_BAD_ACCESS 和 code=1/code=2。这是我的代码:
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.
}
}
我有什么建议吗?
错误link: error link
错误 link 编辑在 Pipeline.swift
我得到答案了! 您所要做的就是检查左侧的身份检查器(实用程序栏),检查 class 和模块是否使用 'RenderView' class 和 GPUImage 模块。