Skip to content

Commit afecb6e

Browse files
committed
update to openCV 3.1 in ios; fix dependencies;
1 parent 7d12c2f commit afecb6e

File tree

117 files changed

+71
-52073
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+71
-52073
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Ignore MacOS DS_Store files
22
.DS_Store
3+
4+
# Ignore framework file since it's bigger than github limit
5+
src/ios/opencv2.framework

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ cordova plugin add https://github.com/Cloudoki/ImageDetectionCordovaPlugin.git
1111
```
1212

1313
### Android
14-
The plugin aims to be used with Android API >= 16 (4.1 Jelly Bean).
14+
- The plugin aims to be used with Android API >= 16 (4.1 Jelly Bean).
1515

1616
### IOS
17-
The plugin aims to be used with iOS version >= 7.
17+
- The plugin aims to be used with iOS version >= 7.
18+
- **Important!** Go into src/ios folder and extract opencv2.framework from the zip file into the same folder.
1819

1920
### Note
2021
In *config.xml* add Android and iOS target preference
@@ -27,6 +28,11 @@ In *config.xml* add Android and iOS target preference
2728
<preference name="deployment-target" value="7.0"/>
2829
</platform>
2930
```
31+
And don't forget to set the background to be transparent or the preview may not shown up.
32+
Again in *config.xml* add the following preference.
33+
```javascript
34+
<preference name="backgroundColor" value="0x00000000" />
35+
```
3036

3137
## Usage
3238
The plugin offers the functions `startProcessing`, `isDetecting` and `setPattern`.

src/ios/ImageDetectionPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import <UIKit/UIKit.h>
2-
#import <opencv2/highgui/cap_ios.h>
2+
#import <opencv2/videoio/cap_ios.h>
33

44
#import <Cordova/CDVPlugin.h>
55

src/ios/ImageDetectionPlugin.mm

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#import "ImageDetectionPlugin.h"
22
#import "ImageUtils.h"
3-
#import <opencv2/highgui/ios.h>
3+
#import <opencv2/imgcodecs/ios.h>
44
#import <opencv2/features2d/features2d.hpp>
5-
#import <opencv2/nonfree/nonfree.hpp>
65

76
using namespace cv;
87

98
@interface ImageDetectionPlugin()
109
{
1110
Mat patt, desc1;
12-
vector<KeyPoint> kp1;
11+
std::vector<KeyPoint> kp1;
1312
bool processFrames, debug, save_files, thread_over, called_success_detection, called_failed_detection;
1413
NSMutableArray *detection;
1514
NSString *callbackID;
@@ -155,9 +154,9 @@ -(void)setBase64Pattern:(NSString *)image_base64
155154
{
156155
UIImageWriteToSavedPhotosAlbum([ImageUtils UIImageFromCVMat:patt], nil, nil, nil);
157156
}
158-
ORB orb;
159-
orb.detect(patt, kp1);
160-
orb.compute(patt, kp1, desc1);
157+
Ptr<ORB> orb = ORB::create();
158+
orb->detect(patt, kp1);
159+
orb->compute(patt, kp1, desc1);
161160
}
162161

163162
- (void)pluginInitialize {
@@ -209,6 +208,7 @@ - (void)pluginInitialize {
209208

210209
[self.camera start];
211210
NSLog(@"----------- CAMERA STARTED ----------");
211+
NSLog(@"----------- CV_VERSION %s ----------", CV_VERSION);
212212
}
213213

214214
#pragma mark - Protocol CvVideoCameraDelegate
@@ -260,18 +260,18 @@ - (void)backgroundImageProcessing:(const Mat &)image
260260
Mat gray = image;
261261
//Mat image_copy = image;
262262
Mat desc2;
263-
vector<KeyPoint> kp2;
263+
std::vector<KeyPoint> kp2;
264264

265265
cvtColor(image, gray, CV_BGRA2GRAY);
266266
//equalizeHist(gray, gray);
267267

268-
ORB orb;
269-
orb.detect(gray, kp2);
270-
orb.compute(gray, kp2, desc2);
268+
Ptr<ORB> orb = ORB::create();
269+
orb->detect(gray, kp2);
270+
orb->compute(gray, kp2, desc2);
271271

272272
BFMatcher bf = BFMatcher::BFMatcher(NORM_HAMMING2, true);
273-
vector<DMatch> matches;
274-
vector<DMatch> good_matches;
273+
std::vector<DMatch> matches;
274+
std::vector<DMatch> good_matches;
275275

276276
if(!desc1.empty() && !desc2.empty())
277277
{
@@ -293,7 +293,7 @@ - (void)backgroundImageProcessing:(const Mat &)image
293293
}
294294
}
295295

296-
vector<DMatch> good_matches_reduced;
296+
std::vector<DMatch> good_matches_reduced;
297297

298298
for(int i = 0; i < size; i++)
299299
{
@@ -312,14 +312,14 @@ - (void)backgroundImageProcessing:(const Mat &)image
312312
if(debug)
313313
{
314314
Mat imageMatches;
315-
drawMatches(patt, kp1, gray, kp2, good_matches_reduced, imageMatches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
315+
drawMatches(patt, kp1, gray, kp2, good_matches_reduced, imageMatches, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);
316316
//image_copy = imageMatches;
317317
}
318318

319319
Mat img_matches = image;
320320
//-- Localize the object
321-
vector<Point2f> obj;
322-
vector<Point2f> scene;
321+
std::vector<Point2f> obj;
322+
std::vector<Point2f> scene;
323323

324324
for( int i = 0; i < good_matches.size(); i++ )
325325
{
@@ -332,23 +332,51 @@ - (void)backgroundImageProcessing:(const Mat &)image
332332

333333
bool result = true;
334334

335-
const double det = H.at<double>(0, 0) * H.at<double>(1, 1) - H.at<double>(1, 0) * H.at<double>(0, 1);
336-
if (det < 0)
337-
result = false;
335+
if (!H.empty()) {
336+
const double p1 = H.at<double>(0, 0);
337+
const double p2 = H.at<double>(1, 1);
338+
const double p3 = H.at<double>(1, 0);
339+
const double p4 = H.at<double>(0, 1);
340+
const double p5 = H.at<double>(2, 0);
341+
const double p6 = H.at<double>(2, 1);
342+
double det = 0, N1 = 0, N2 = 0, N3 = 0;
343+
344+
if (p1 && p2 && p3 && p4) {
345+
det = p1 * p2 - p3 * p4;
346+
if (det < 0)
347+
result = false;
348+
} else {
349+
result = false;
350+
}
338351

339-
const double N1 = sqrt(H.at<double>(0, 0) * H.at<double>(0, 0) + H.at<double>(1, 0) * H.at<double>(1, 0));
340-
if (N1 > 4 || N1 < 0.1)
341-
result = false;
352+
if (p1 && p3) {
353+
N1 = sqrt(p1 * p1 + p3 * p3);
354+
if (N1 > 4 || N1 < 0.1)
355+
result = false;
356+
} else {
357+
result = false;
358+
}
342359

343-
const double N2 = sqrt(H.at<double>(0, 1) * H.at<double>(0, 1) + H.at<double>(1, 1) * H.at<double>(1, 1));
344-
if (N2 > 4 || N2 < 0.1)
345-
result = false;
360+
if (p2 && p4) {
361+
N2 = sqrt(p4 * p4 + p2 * p2);
362+
if (N2 > 4 || N2 < 0.1)
363+
result = false;
364+
} else {
365+
result = false;
366+
}
346367

347-
const double N3 = sqrt(H.at<double>(2, 0) * H.at<double>(2, 0) + H.at<double>(2, 1) * H.at<double>(2, 1));
348-
if (N3 > 0.002)
349-
result = false;
368+
if (p5 && p6) {
369+
N3 = sqrt(p5 * p5 + p6 * p6);
370+
if (N3 > 0.002)
371+
result = false;
372+
} else {
373+
result = false;
374+
}
350375

351-
//NSLog(@"det %f, N1 %f, N2 %f, N3 %f, result %i", det, N1, N2, N3, result);
376+
//NSLog(@"det %f, N1 %f, N2 %f, N3 %f, result %i", det, N1, N2, N3, result);
377+
} else {
378+
result = false;
379+
}
352380

353381
if(result)
354382
{
@@ -361,10 +389,10 @@ - (void)backgroundImageProcessing:(const Mat &)image
361389
if(debug)
362390
{
363391
//-- Get the corners from the image_1 ( the object to be "detected" )
364-
vector<Point2f> obj_corners(4);
392+
std::vector<Point2f> obj_corners(4);
365393
obj_corners[0] = cvPoint(0,0); obj_corners[1] = cvPoint( patt.cols, 0 );
366394
obj_corners[2] = cvPoint( patt.cols, patt.rows ); obj_corners[3] = cvPoint( 0, patt.rows );
367-
vector<Point2f> scene_corners(4);
395+
std::vector<Point2f> scene_corners(4);
368396

369397
perspectiveTransform( obj_corners, scene_corners, H);
370398

src/ios/opencv2.framework/Headers

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/ios/opencv2.framework/Resources

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)