using namespace cv; Xcode doesn't recognize face detection - iphone

I have a problem with OpenCV.
the system doesn't recognize the cv that is called in my .h file.
when I type using namespace cv;
and I command click on cv, it links to the framework.
The other weird thing is my program works in a new file project. It does recognized the cv.
when I add to my existing project, it shows an error for using namespace cv; and cascade classifier, both can't be recognized. thanks!!
Here's
#import <UIKit/UIKit.h>
#import <opencv2/highgui/cap_ios.h>
#import <opencv2/imgproc/imgproc_c.h>
#import <opencv2/objdetect/objdetect.hpp>
using namespace cv; ----->expected ; after top level declarator
#interface CoolViewController : UIViewController<CvVideoCameraDelegate>
{
IBOutlet UIImageView* imageView;
CvVideoCamera* videoCamera;
CascadeClassifier faceCascade; ---->unknown type CascadeClassifier did you mean cv::CascadeClassifier
}
#property (nonatomic, retain) CvVideoCamera* videoCamera;
- (IBAction)startCamera:(id)sender;
- (IBAction)stopCamera:(id)sender;
#end

It is because xcode cannot recognize using namespace in ObjC code. Make sure you files are .mm extension not .m
Also please don't put using namespace in header file and try to avoid any C++ code in ObjC header file
You should to move your ivars to .mm file
#implementation CoolViewController
{
IBOutlet UIImageView* imageView;
CvVideoCamera* videoCamera;
CascadeClassifier faceCascade;
}
// your methods
#end

Related

Protocol error. Cannot find protocol declaration

We have error: cannot find protocol declaration for 'ClassWhichUseMainScene' [3]
We created file:
Protocol.h
#import "ScoreSystem.h"
#import "OtherSystem"
#import "OtherSystem2"
#class ScoreSystem;
#protocol SceneDelegate <NSObject>
#property (nonatomic, readonly,retain) ScoreSystem* score;
#property (nonatomic, readonly,retain) OtherSystem* system;
#property (nonatomic, readonly,retain) OtherSystem2* system2;
#end
And use in ScoreSystem.h
#import "Protocol.h"
#import "OtherSystem"
#import "OtherSystem2"
#interface ScoreSystem: NSObject <SceneDelegate>
{
OtherSystem* system;
OtherSystem2* system2;
}
In ScoreSystem we want use just OtherSystem and OtherSystem2 objects. In OtherSystem use ScoreSystem and OtherSystem2, etc.
We want create universal protocol for all system.
You have a circular dependency between your two header files (each imports the other). Do not import ScoreSystem.h in Protocol.h, the #class forward declaration is enough. The same goes for your other two imports.
As a general rule I avoid including class header files in other class header files - I just use #class everywhere and import the headers in the implementation files.
Mine Problem resolved with simple import statement
#import "ProtocolContainingFile.h"

Objective C Properties

I tried searching for this issue, but can't seem to find out what I'm doing wrong.
Here is my controller header:
#import <UIKit/UIKit.h>
#interface BabyLearnViewController : UIViewController {
UIButton *btnImage;
MediaManager* myMediaManager;
}
#property (nonatomic, retain) IBOutlet UIButton *btnImage;
#property (retain) MediaManager* myMediaManager;
- (IBAction)setNewImage;
#end
Here is my controller class:
#import "BabyLearnViewController.h"
#import "MediaManager.h";
#implementation BabyLearnViewController
#synthesize btnImage;
#synthesize myMediaManager;
I am getting the errors:
error: expected specifier-qualifier-list before 'MediaManager'
error: no declaration of property 'myMediaManager' found in the interface
Any ideas? Usually the 1st error comes up if you have a cylical reference. 'MediaManager' doesn't reference anything else. Any ideas?
Since you have no mentions of MediaManager class at the moment it is used in header file compiler can't figure out what "MediaManager" is and issues an error. Declare that class using forward declaration in your header file to let compiler know that MediaManager is actually a class:
#class MediaManager;
#interface BabyLearnViewController : UIViewController {
...
P.S. As an alternative you can import MediaManager.h in your header, but using forward declaration is preferred.
Place #import "MediaManager.h"
this in header file of BabyLearnViewController
try add #class MediaManager; before #interface

Problem in Importing File

I am importing File "FieldActivityViewController.h".But Showing an error
"/Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h:22:0
Expected specifier-qualifier-list
before 'FieldActivityViewController'
in /Users/rupeshnandha/Downloads/AQMD
Release 3/Classes/InputChoice.h"
As is a code Written in "InputChoice.h"
#import "FieldActivityViewController.h"
#protocol InputChoiceProtocol <NSObject>
#required
-(void) inputChoiceSelectedIndex :(int) index;
#end
#interface InputChoice : UIViewController {
//NSString *keyString;
FieldActivityViewController *field_act;
NSMutableArray *selectionArray;
IBOutlet UITableView *table;
NSObject<InputChoiceProtocol> *delegate;
// IBOutlet UIPickerView *picker;
}
#property (nonatomic,retain) NSArray *selectionArray;
#property (nonatomic,retain) FieldActivityViewController *field_act;
#property (nonatomic,retain) NSObject<InputChoiceProtocol> *delegate;
#end
It's not the good practice to import the application classes in .h files.
Try with forward class declaration and import you FieldActivityViewController file in .h
Use with forward class declaration #class FieldActivityViewController; at the place of your import statement.
use #class FieldActivityViewController
Most likely cause is that you have a circular dependency. InputChoice.h imports FieldActivityViewController.h and FieldActivityViewController.h imports InputChoice.h (not necessarily directly).
The best solution is to move the imports out of the header file into the .m file and put
#class FieldActivityViewController;
in InputChoice.h and
#class InputChoice
in FieldActivityViewController.h (or whichever header has InputChoic.h in it.

error: expected specifier-qualifier-list beforeā€¦

I am not sure why I got this error in the DetailViewController.. the header is included no spelling mistake. tried cleaning the project and build it
#import <UIKit/UIKit.h>
#import "Conversation.h"
#import "Login.h"
#import "DetailViewController.h"
#interface DetailMessageViewController : UIViewController<RKObjectLoaderDelegate, UITableViewDataSource, UITableViewDelegate, MHLazyTableImagesDelegate> {
DetailViewController * detailViewController; //error: expected specifier-qualifier-list before
UITableView * tableView;
NSMutableArray * messages;
MHLazyTableImages* lazyImages;
}
#property (nonatomic, retain) NSMutableArray * messages;
#property (nonatomic, retain) IBOutlet UITableView * tableView;
#property (nonatomic, retain) DetailViewController * detailViewController;
#end
Perhaps you have circularly dependent imports. Is the header file for DetailMessageViewController also included in DetailViewController.h or Login.h or Conversation.h?
Oh, one of these. I hate these.
Most likely, it is because of the protocols are not declared (or misspelled). Or it is because there is a syntax error in a header that causes the compiler to fail to close an expression or scope. Or it could be a syntax error near where the header file was imported in the .m file.
In any case, a pain in the butt. What you can do, though, is grab the compiler command line and put -E in it; that'll cause the compiler to precompile everything and dump exactly what it was going to compile into what should be the .o (you can change that name, too). Then, if you look at where the above line of code falls, the line causing the error should be nearby, even if from a different header

Adding C++ Object to Objective-C Class

I'm trying to mix C++ and Objective-C, I've made it most of the way but would like to have a single interface class between the Objective-C and C++ code. Therefore I would like to have a persistent C++ object in the ViewController interface.
This fails by forbidding the declaration of 'myCppFile' with no type:
#import <UIKit/UIKit.h>
#import "GLView.h"
#import "myCppFile.h"
#interface GLViewController : UIViewController <GLViewDelegate>
{
myCppFile cppobject;
}
#end
However this works just fine in the .mm implementation file (It doesn't work because I want cppobject to persist between calls)
#import "myCppFile.h"
#implementation GLViewController
- (void)drawView:(UIView *)theView
{
myCppFile cppobject;
cppobject.draw();
}
You should use opaque pointers and only include C++ headers in the file that implements your Objective-C class. That way you don't force other files that include the header to use Objective-C++:
// header:
#import <UIKit/UIKit.h>
#import "GLView.h"
struct Opaque;
#interface GLViewController : UIViewController <GLViewDelegate>
{
struct Opaque* opaque;
}
// ...
#end
// source file:
#import "myCppFile.h"
struct Opaque {
myCppFile cppobject;
};
#implementation GLViewController
// ... create opaque member on initialization
- (void)foo
{
opaque->cppobject.doSomething();
}
#end
Make sure that all files that include GLViewController.h are Objective-C++ sources (*.mm).
When you include C++ code in the header of your view controller, all sources that import this header must be able to understand it, so they must be in Objective-C++
You need to declare the C++ objects in an interface block in your .mm file.
In .mm:
#include "SomeCPPclass.h"
#interface SomeDetailViewController () {
SomeCPPclass* _ipcamera;
}
#property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)blabla;
#end
I think you need to set the following flag to true in your project settings:
GCC_OBJC_CALL_CXX_CDTORS = YES
This should allow you to instantiate C++ objects in your Objective-C classes.