Appcelerator iOS Module with OpenCV - OpenCV's camera won't open - objective-c

So, I am developing an Appcelerator iOS Module which uses OpenCV to do some image processing with the camera.
The thing is, the camera won't open at all. I read the official OpenCV example, followed the steps (of course, had to adapt things to be used as an Appc Module), also followed the iOSModuleQuickStart from the Appcelerator Wiki. I thought I did it right, except that it just doesn't work.
This is my .h View class from the Module:
#import "TiUIView.h"
#import <Foundation/Foundation.h>
#import <opencv2/videoio/cap_ios.h>
#import <UIKit/UIKit.h>
using namespace cv;
#interface ComIosopencvmoduleTestView : TiUIView<CvPhotoCameraDelegate>
{
UIImageView *imageView;
CvPhotoCamera *photoCamera;
}
#property (nonatomic, retain) CvPhotoCamera* photoCamera;
#end
This is the implementation of it (.mm):
#import "ComIosopencvmoduleTestView.h"
#import "TiUtils.h"
// some other imports....
#implementation ComIosopencvmoduleTestView
#synthesize photoCamera;
#pragma mark - UI Actions
- (void)initializeState
{
self.photoCamera = [[CvPhotoCamera alloc] initWithParentView:imageView];
self.photoCamera.delegate = self;
self.photoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.photoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetPhoto;
self.photoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.photoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
[self.photoCamera start];
// The instantiation and the call to start method, should do the trick, but it doesn't
}
#end
And, this is how I call it on JS, from Appcelerator Studio:
var VWindow = Ti.UI.createWindow({});
var VView = VItire.createView({});
var VItire = require('com.iosopencvmodule.test');
VWindow.add(VView);
VWindow.open();
This code, according to what I understood from both Tutorials, OpenCV and Appcelerator, should be enough to open the Camera as the App is launched.
Please, what could possibly be wrong? I am going mad with this. Thanks in advance!
Please help!

Related

Objective-C warning: Class 'ViewController' does not conform to protocol 'CBPeripheralManagerDelegate'

I'm trying to create an Obj-C, CoreBluetooth virtual peripheral app and get this warning.
//
// ViewController.h
// sim_backend_empty3
//
//
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
#interface ViewController : UIViewController <CBPeripheralManagerDelegate>
#property (nonatomic, strong) CBPeripheralManager *peripheralManager;
#end
//
// ViewController.m
// sim_backend_empty3
//
//
#import "ViewController.h"
#implementation ViewController >>>>>>>>>> WARNING >>>>>>>>>> Class 'ViewController' does not conform to protocol 'CBPeripheralManagerDelegate'
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)start_BLE_advertisements
{
[[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil];
}
#end
You need to implement the required CBPeripheralManagerDelegate protocol method:
peripheralManagerDidUpdateState:
as mentioned in the documentation here: https://developer.apple.com/documentation/corebluetooth/cbperipheralmanagerdelegate?language=objc
The protocol’s required one method, peripheralManagerDidUpdateState:, which Core Bluetooth calls whenever the peripheral manager’s state updates to indicate whether the peripheral manager is available.
You can check out an Objective-C example of how to setup CoreBluetooth using this repo:
https://github.com/LGBluetooth/LGBluetooth
Back when I still coded in ObjC, it was the library I used - and it was pretty great.
At the very least, it will give you some ideas on how you should be implementing the interfaces.
Here is a Swift implementation of what it sounds like you're trying to do (based on your other question asked a few days ago). Maybe you can backport it to ObjC (disclaimer: I'm the author).
https://github.com/RobotPajamas/SwiftyTeeth/blob/master/Sources/SwiftyTooth/SwiftyTooth.swift

outsourcing code

My iPhone game has a lot of recurring code (move pictures, add score), that makes it too big when repeating the same code on each button click.
this is ViewController.m
interface and implementation between Viewcontroller.h and ViewController.m is correct - workes well
- (IBAction)button_xx_pressed:(id)sender
{
//trying to call the outsourced code
[self this_is_a_test];
}
so I tried to make outsourced recurring code. I don't need method or functions that gives a result back or something. Just do some action like NSLog output...(just a test). Or in the original version - move pictures, add score and other stuff.
this is Outsourcing.h
#import "Outsourcing.m"
#end
this is Outsourcing.m
#import "Outsourcing.h"
- (void)this_is_a_test {
int test_variable = 999;
NSLog(#"Give me a test output: = %i", test_variable);
}
#end
this would shrink the size of my game more than 80% (very important). I have thousands of recurring programming lines and at the moment, I don't know how to handle it.
actual error messages:
Outsourcing.h => missing context for method declaration
Outsourcing.m => missing context for method declaration
=> #end must appear in Objective-C context
Anyone any hints for me? Thank you very much... The rest of my game is ok... everything would run without issues. I'm very glad that I got it running (but the game size is a problem).
1 or 2 months ago, I never used xcode before. I just had some experience in VBA. And what I want is similar to.
=> Call this_is_a_test
=> Private Sub this_is_a_test()
But it seems I'm too stupid :-(
thanks
#interface Outsourcing : NSObject
- (void)this_is_a_test;
#end
#import "Outsourcing.h"
#implementation
- (void)this_is_a_test {
int test_variable = 999;
NSLog(#"Give me a test output: = %d", test_variable);
}
#end
and you call it like this in your ViewController:
#import "Outsourcing.h"
...
- (IBAction)button_xx_pressed:(id)sender
{
Outsourcing *outsourcing = [[[Outsourcing alloc] init] autorelease];
//trying to call the outsourced code
[outsourcing this_is_a_test];
}
You are missing
#interface Outsourcing : NSObject
in your header file (Outsourcing.h). Remove:
#import "Outsourcing.m"
You import header files, not source files....You are also missing:
#implementation Outsourcing
In your .m file, just after the import declaration.

Implementing Facebook iOS SDK - no "fbDidLogin" callback

I was following integration steps from official FB documentation and have implemented "login" and "post to wall" features of the SDK, and everything ok, but the problem is that its working only if Im using main app delegate .h/.m files.
But currently I need to put it into another .h/.m file - login works, but "fbDidLogin" callback never calls, I used NSLog to check. Im not very good with ObjC, and using a game-engine, so I guess I missed some private/public declaration stuff etc.. Can you please lead me in right direction to fix it? Thanks in advance!
code looks like this:
.h
#import "FBConnect.h"
...
#interface S3DEngine_EAGLView : UIView <UITextFieldDelegate, FBSessionDelegate>
{
#public Facebook *facebook;
#private
...
EAGLContext *pEAGLContext ;
...
}
#property NSTimeInterval iAnimationInterval;
#property(nonatomic, retain) NSMutableDictionary *achievementsDictionary;
#property (nonatomic, retain) Facebook *facebook;
...
.m
#implementation S3DEngine_EAGLView
...
#synthesize facebook;
...
- (void)fbDidLogin {
}
...
It will be fired in case you assign the Facebook delegate to your viewController .. and thats what I think because you are defining a property for the Facebook instance , are you assigning it to the one in the app delegate ? if so just move the Facebook implementation from the app delegate to your viewController.

No access to global instance (build by factory) on iOS

this is a follow-up question to my last one here: iOS: Initialise object at start of application for all controllers to use .
I have set my application up as follows (ignore the DB Prefix):
DBFactoryClass // Built a DataManaging Object for later use in the app
DBDataModel // Is created by the factory, holds all data & access methods
DBViewControllerA // Will show some of the data that DBDataModel holds
moreViewControllers that will need access to the same DBDataModel Object
i will go step by step through the application, and then post the problem in the end
AppDelegate.h
#import "DBFactoryClass.h"
AppDelegate.m
- (BOOL)...didFinishLaunching...
{
DBFactoryClass *FACTORY = [[DBFactoryClass alloc ]init ];
return YES;
}
DBFactoryClass.h
#import <Foundation/Foundation.h>
#import "DBDataModel.h"
#interface DBFactoryClass : NSObject
#property (strong) DBDataModel *DATAMODEL;
#end
DBFactoryClass.m
#import "DBFactoryClass.h"
#implementation DBFactoryClass
#synthesize DATAMODEL;
-(id)init{
self = [super init];
[self setDATAMODEL:[[DBDataModel alloc]init ]];
return self;
}
#end
ViewControllerA.h
#import <UIKit/UIKit.h>
#import "DBDataModel.h"
#class DBDataModel;
#interface todayViewController : UIViewController
#property (strong)DBDataModel *DATAMODEL;
#property (weak, nonatomic) IBOutlet UILabel *testLabel;
#end
ViewControllerA.m
#import "todayViewController.h"
#implementation todayViewController
#synthesize testLabel;
#synthesize DATAMODEL;
- (void)viewDidLoad
{
todaySpentLabel.text = [[DATAMODEL test]stringValue]; // read testdata
}
#end
DBDataModel.h
#import <Foundation/Foundation.h>
#interface DBDataModel : NSObject
#property (nonatomic, retain) NSNumber* test;
#end
DBDataModel.m
#import "DBDataModel.h"
#implementation DBDataModel
#synthesize test;
-(id)init{
test = [[NSNumber alloc]initWithInt:4]; // only a testvalue
return self;
}
#end
the app builds fine, and starts up but the label stays blank. so either the object does not exist (but i guess this would result in an error message), or something else is wrong with my setup. any thoughts?
Two notes:
Your have a shotgun approach to asking questions: everytime you hit a stumbling block, you ask a question and if the answer does not work immediately, you ask another one. You have to spend some energy in between the questions debugging and poking into the code on your own, otherwise you will depend on the external help forever.
Use the common coding style please. CAPS are reserved for macros.
Now to the code:
- (BOOL) …didFinishLaunching…
{
DBFactoryClass *factory = [[DBFactoryClass alloc] init];
return YES;
}
This simply creates an instance of the DBFactoryClass and then throws it away. In other words, it’s essentially a no-op. Judging by the comments in the previous answer you create the controllers using the Storyboard feature. How are they supposed to receive the reference to the data model? The reference isn’t going to show up by magic, you have to assign it somewhere.
I’m not familiar with the Storyboard feature. The way I would do it is to create the view controllers using separate XIB files, then you can create the controller instances in the Factory class and pass them the needed reference to the model. In the end the application delegate would create the factory, ask it to assemble the main controller and then set it as the root view controller for the window. Just like in my sample project. It’s possible that there’s a way to make it work with storyboards, but as I said, I am not familiar with them.

Error: expected specifier-qualifier-list before 'QTVisualContextRef'

I am currently getting this error message in my header code, and I'm not sure as to why:
"Error: expected specifier-qualifier-list before 'QTVisualContextRef'"
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <OpenGL/OpenGL.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreVideo/CoreVideo.h>
#interface MyRecorderController : NSObject {
IBOutlet QTCaptureView *mCaptureView;
IBOutlet NSPopUpButton *videoDevicePopUp;
NSMutableDictionary *namesToDevicesDictionary;
NSString *defaultDeviceMenuTitle;
CVImageBufferRef mCurrentImageBuffer;
QTCaptureDecompressedVideoOutput *mCaptureDecompressedVideoOutput;
QTVisualContextRef qtVisualContext; // the context the movie is playing in
// filters for CI rendering
CIFilter *colorCorrectionFilter; // hue saturation brightness control through one CI filter
CIFilter *effectFilter; // zoom blur filter
CIFilter *compositeFilter; // composites the timecode over the video
CIContext *ciContext;
QTCaptureSession *mCaptureSession;
QTCaptureMovieFileOutput *mCaptureMovieFileOutput;
QTCaptureDeviceInput *mCaptureDeviceInput;
}
#end
In the examples I have seen through other code (e.g. Cocoa Video Tutorial) I have not seen any difference in their code to mine. If anyone would be able to point out as to how this error could have occurred that would be great.
Thanks heaps! :)
If you are compiling as a 64-bit application, QTVisualContextRef is not available to you. You'll need to compile the application as 32-bit.
Apple hasn't fully fleshed out QTKit to be 64-bit quite yet...
That's a GCC error and it means the token QTVisualContextRef is not known to the compiler. It's a rather poor error message indeed. You need to add the correct #import that will teach the compiler about this type. It's part of the QuickTime framework, so you probably want
#import <QuickTime/QuickTime.h>