当我们单击反应本机组件中的按钮时,我想打开 ios 的本机相机。然后我想为 Opencv 方法处理实时相机。
我创建了视图控制器和 UI,但它不工作。
我用 Imageview 和按钮创建故事板。这是 viewcontroller.h 文件,简而言之,我在 react native 组件中有按钮。当我单击按钮时,它应该打开 Native ios Camera。我只是卡在这里,我需要帮助。请在 React native 中访问 nativeCamera 的任何解决方案。
#import <opencv2/highgui/cap_ios.h>
using namespace cv;
@interface ViewController : UIViewController
{
IBOutlet UIImageView* imageView;
IBOutlet UIButton* button;
CvVideoCamera* videoCamera;
}
- (IBAction)actionStart:(id)sender;
@property (nonatomic, retain) CvVideoCamera* videoCamera;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
self.videoCamera.grayscale = NO;
}
- (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, COLOR_BGR2GRAY);
// invert image
bitwise_not(image_copy, image_copy);
//Convert BGR to BGRA (three channel to four channel)
Mat bgr;
cvtColor(image_copy, bgr, COLOR_GRAY2BGR);
cvtColor(bgr, image, COLOR_BGR2BGRA);
}
-(IBAction)actionStart:(id)sender
{
[self.videoCamera start];
}
@end
and My AppDelegate i call this method
RCT_EXPORT_METHOD(pushVC:(NSString *)vcName){
UIViewController *vc = [UIStoryboard storyboardWithName:@"Camera" bundle:nil].instantiateInitialViewController;
self.window.rootViewController = vc;
}`