5
Uygulamamda iki görüntünün RGB'sinin aynı olup olmadığını karşılaştırmam gerekiyor. Bu kodu kullanıyorum ... İki resmin RGB'sini IOS ile karşılaştırın
-(CGFloat)compareImage:(UIImage *)imgPre capturedImage:(UIImage *)imgCaptured
{
int colorDiff;
CFDataRef pixelData = CGDataProviderCopyData(CGImageGetDataProvider(imgPre.CGImage));
int myWidth = (int)CGImageGetWidth(imgPre.CGImage)/2;
int myHeight =(int)CGImageGetHeight(imgPre.CGImage)/2;
const UInt8 *pixels = CFDataGetBytePtr(pixelData);
int bytesPerPixel_ = 4;
int pixelStartIndex = (myWidth + myHeight) * bytesPerPixel_;
UInt8 alphaVal = pixels[pixelStartIndex];
UInt8 redVal = pixels[pixelStartIndex + 1];
UInt8 greenVal = pixels[pixelStartIndex + 2];
UInt8 blueVal = pixels[pixelStartIndex + 3];
UIColor *color = [UIColor colorWithRed:(redVal/255.0f) green:(greenVal/255.0f) blue:(blueVal/255.0f) alpha:(alphaVal/255.0f)];
NSLog(@"color of image=%@",color);
NSLog(@"color of R=%hhu/G=%hhu/B=%hhu",redVal,greenVal,blueVal);
CFDataRef pixelDataCaptured = CGDataProviderCopyData(CGImageGetDataProvider(imgCaptured.CGImage));
int myWidthCaptured = (int)CGImageGetWidth(imgCaptured.CGImage)/2;
int myHeightCaptured =(int)CGImageGetHeight(imgCaptured.CGImage)/2;
const UInt8 *pixelsCaptured = CFDataGetBytePtr(pixelDataCaptured);
int pixelStartIndexCaptured = (myWidthCaptured + myHeightCaptured) * bytesPerPixel_;
UInt8 alphaValCaptured = pixelsCaptured[pixelStartIndexCaptured];
UInt8 redValCaptured = pixelsCaptured[pixelStartIndexCaptured + 1];
UInt8 greenValCaptured = pixelsCaptured[pixelStartIndexCaptured + 2];
UInt8 blueValCaptured = pixelsCaptured[pixelStartIndexCaptured + 3];
UIColor *colorCaptured = [UIColor colorWithRed:(redValCaptured/255.0f) green:(greenValCaptured/255.0f) blue:(blueValCaptured/255.0f) alpha:(alphaValCaptured/255.0f)];
NSLog(@"color of captured image=%@",colorCaptured);
NSLog(@"color of captured image R=%hhu/G=%hhu/B=%hhu",redValCaptured,greenValCaptured,blueValCaptured);
colorDiff=sqrt((redVal-249)*(redVal-249)+(greenVal-greenValCaptured)*(greenVal-greenValCaptured)+(blueVal-blueValCaptured)*(blueVal-blueValCaptured));
return colorDiff;
}
ama adıyla görüntüyü kuruyorum bu yöntem döndürür aynı RGB değeri.
Yönteminizde 'imgCaptured' kullanamazsınız. Bu tuhaf. – Larme
, delege yönteminden görüntüyü yakaladıktan sonra bu yöntemi çağırıyor olabilir. @ Larme –
@Larme: Üzgünüm, yanlışlıkla yanlış bir kod yayınladım ... lütfen uodated kodu kontrol edin ... imgCaptured görüntüsü burada saklanır ve imgPre şu anda kamera ile çekilen görüntüdür. Ben farklı görüntü için –