LBXScan
LBXScan copied to clipboard
使用ZXing,CPU使用率直接飙到99,希望作者查看一下!
使用ZXing,CPU使用率直接飙到99,希望作者查看一下! 手机发热很严重,希望作者能看看什么情况,我用instrument查了,是因为一直在掉一个方法
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection。、 这个方法
我的也是,用的demo,真机测试,扫条形码时,它会一直调用didOutputSampleBuffer方法,内存飚的好高
还以为是作者回复了,小失落
最近比较忙,我只是调用ZXing的库,对ZXing本身也不是很懂,你也可以调一下看看问题出在那里啊,不过网上很多文章也是说ZXing比较占用CPU
好吧。
在这个方法(LBXZXCapture.m - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection)里面加一句
[NSThread sleepForTimeInterval:0.5];
我感觉是运算密集,计算图像中包含的二维码条形码, 实际情况不需要那么快, 让线程休息0.5秒,测试cpu降低到20 - 40 %.
#123 #83
如果pod 的ZXing 可以对LBXZXCapture 加一个扩展 + (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(captureOutput:didOutputSampleBuffer:fromConnection:);
SEL swizzledSelector = @selector(hd_captureOutput:didOutputSampleBuffer:fromConnection:);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (void)hd_captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { [self hd_captureOutput:captureOutput didOutputSampleBuffer:sampleBuffer fromConnection:connection]; [NSThread sleepForTimeInterval:0.5]; }
实测 @zxldev 方法可行 谢谢
@zxldev 谢谢你,但还是温温的,即使关了扫描界面
每次进入页面都要先黑屏一会再显示摄像头,能不能做到跟其他的一样,一进来快速显示摄像头调用界面
@2282128950 分析源码之后发现,原因是作者在viewDidAppear:中才调用startScan ,所以才会慢半拍。