How to compare images using opencv in iOS (iPhone) -


i want compare 2 images taken iphone camera in project. using opencv doing that. there other better way that? if got % similarity, great.

i using opencv following code image comparison:

-(void)opencvimagecompare{   nsmutablearray *valuesarray=[[nsmutablearray alloc]init];  iplimage *img = [self createiplimagefromuiimage:imageview.image]; // check camera image  if(img == 0) {    printf("cannot load camera img");  }  iplimage  *res;  cvpoint   minloc, maxloc; double    minval, maxval; double values;  uiimage *imagetocompare = [uiimage imagenamed:@"myimagename"]; iplimage *imagetocompareipl = [self createiplimagefromuiimage:imagetocompare]; // check server image  if(imagetocompareipl == 0) {     printf("cannot load serveriplimagearray image"); } if(img->width-imagetocompareipl->width<=0 && img->height-imagetocompareipl->height<=0){     int balwidth=imagetocompareipl->width-img->width;     int balheight=imagetocompareipl->height-img->height;     img->width=img->width+balwidth+100;     img->height=img->height+balheight+100; }    cvsize size = cvsize(                      img->width  - imagetocompareipl->width  + 1,                      img->height - imagetocompareipl->height + 1                      );  res = cvcreateimage(size, ipl_depth_32f, 1);  // cv_tm_sqdiff cv_tm_sqdiff_normed // cv_tm_ccorr  cv_tm_ccorr_normed // cv_tm_ccoeff cv_tm_ccoeff_normed  cvmatchtemplate(img, imagetocompareipl, res,cv_tm_ccoeff); cvminmaxloc(res, &minval, &maxval, &minloc, &maxloc, 0); printf("\n value %f", maxval-minval); values=maxval-minval; nsstring *valstring=[nsstring stringwithformat:@"%f",values]; [valuesarray addobject:valstring]; weedobject.values=[valstring doublevalue]; printf("\n------------------------------");  cvreleaseimage(&imagetocompareipl);  cvreleaseimage(&res); } cvreleaseimage(&img);  } 

for same image getting non 0 result (14956...) , if pass different image crash.

try code, compares images bit bit, ie 100%

uiimage *img1 = // photo; uiimage *img2 = // photo;  nsdata *imgdata1 = uiimagepngrepresentation(img1);  nsdata *imgdata2 = uiimagepngrepresentation(img2);  if ([imgdata1 isequaltodata:imgdata2])  { nslog(@"same image"); } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -