New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥🔥🔥 [Guide] How to use this lib in iOS #90
Comments
If possible, could you submit a pull request with the iOS example and
HowTo? I will merge your files submitted to the repository.
…On Fri, Mar 15, 2019 at 11:08 AM Robin ***@***.***> wrote:
This lib is very useful! I try it in iOS and successful run.
1. download or clone this lib in your computer;
2. create New Xcode project;
3. add this lib's src to your project;
4. add the system lib libc++.tbd and other you need framework(eg.
ACFoundation.framework etc.);
5. download opencv2.framework and add it in your project;
6. follow the example file to write the code.
*!!!*
1. modify facedetectcnn.h
//#define _ENABLE_AVX2 //Please enable it if X64 CPU
#define _ENABLE_NEON //Please enable it if ARM CPU
1. modify .m to .mm
2. import lib in your .mm
#import <opencv2/opencv.hpp>
#import <opencv2/imgcodecs/ios.h>
#import "ViewController.h"
#import "facedetectcnn.h"
you must import the opencv2/opencv.hpp first !!!
MyCode:
#import <opencv2/opencv.hpp>
#import <opencv2/imgcodecs/ios.h>
#import "ViewController.h"
#import "facedetectcnn.h"
//define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;
@implementation ViewController
- (UIImage *)loadImageAndDectect:(const char *)image_file{
Mat img = imread(image_file);
if (img.empty()) {
fprintf(stderr, "Can not load the image file %s.\n", image_file);
return nil;
}
int *pResults = NULL;
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer) {
fprintf(stderr, "Can not alloc buffer.\n");
return nil;
}
pResults = facedetect_cnn(pBuffer, (unsigned char *)(img.ptr(0)), img.cols, img.rows, (int)img.step);
printf("%d faces detected.\n", (pResults ? *pResults : 0));
Mat result_cnn = img.clone();;
//print the detection results
for(int i = 0; i < (pResults ? *pResults : 0); i++)
{
short * p = ((short*)(pResults+1))+142*i;
int x = p[0];
int y = p[1];
int w = p[2];
int h = p[3];
int neighbors = p[4];
int angle = p[5];
printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x,y,w,h,neighbors, angle);
rectangle(result_cnn, cv::Rect(x, y, w, h), Scalar(0, 255, 0), 2);
}
free(pBuffer);
return MatToUIImage(result_cnn);
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
imageView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:imageView];
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@".jpg"];
imageView.image = [self loadImageAndDectect:[path UTF8String]];
}
@EnD
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#90>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AG0eHZARHGfnU58IRciLvhUYPu87O-ICks5vWw6hgaJpZM4b1ndz>
.
|
@RobinChao Do you have the running time on IOS. I tested it on iphone 6s and iphone x, much slower than the raspberry platform |
@ewen1024 Sorry, i didn't have the running time. Did you input huge image to NN, if you resize the image or use small size image, maybe running faster a little. Thanks. |
Thx for your reply. |
Currently no OpenMP support in the source code. I will add it soon.
…On Thu, Apr 25, 2019 at 11:37 AM ewen1024 ***@***.***> wrote:
Thx for your reply.
By enabling neon int8 and optimization -o3, I already got the running time
in 100ms.
But I failed to enable openmp on ios which said the library only supports
x86. Do you have any idea on this?\
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWR4HKJONSUK2MG6RT4M33PSERPVANCNFSM4G6WO5ZQ>
.
|
Sorry for the wrong reply. You can compile the source code with -fopenmp
(GCC) to enable OpenMP.
…On Thu, Apr 25, 2019 at 12:00 PM Shiqi Yu ***@***.***> wrote:
Currently no OpenMP support in the source code. I will add it soon.
On Thu, Apr 25, 2019 at 11:37 AM ewen1024 ***@***.***>
wrote:
> Thx for your reply.
> By enabling neon int8 and optimization -o3, I already got the running
> time in 100ms.
> But I failed to enable openmp on ios which said the library only supports
> x86. Do you have any idea on this?\
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#90 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABWR4HKJONSUK2MG6RT4M33PSERPVANCNFSM4G6WO5ZQ>
> .
>
|
@ShiqiYu On ios platform, it seems the compiler clang doesn't support openmp. |
You can change the macro _OPENMP in the source code to the clang supported
code.
According to my experiments, OpenMP cannot improve the speed obviously on
Intel platform.
…On Thu, Apr 25, 2019 at 12:09 PM ewen1024 ***@***.***> wrote:
@ShiqiYu <https://github.com/ShiqiYu> On ios platform, it seems the
compiler clang doesn't support openmp.
So I can't compile the code with -fopenmp. Maybe I need to find a way to
add support of openmp for the clang
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABWR4HMKS5K5HVOG2MLGEM3PSEVGBANCNFSM4G6WO5ZQ>
.
|
@ShiqiYu appreciate for your help! |
请问一下为什么在ios上图片变色了, 或者使用opencv的ios的函数UIImageToMat, 无法识别出人脸 |
This lib is very useful! I try it in iOS and successful run.
libc++.tbd
and other you need framework(eg. ACFoundation.framework etc.);opencv2.framework
and add it in your project;!!!
facedetectcnn.h
.m
to.mm
.mm
MyCode:
The text was updated successfully, but these errors were encountered: