-1

iOSでECG波形のピーク値を見つける必要があるため、最初に色検出コードを適用してその黒い波形を検出し、次にそのピクセルの座標を見つけました

   CGImageRef imgSource = self.ImageView.image.CGImage;
CFDataRef m_DataRed1 = CGDataProviderCopyData(CGImageGetDataProvider(imgSource));
CGFloat myheight;
CGFloat mywidth;
myheight= CGImageGetHeight(imgSource);
mywidth = CGImageGetWidth(imgSource);
UInt8 *dataOrignal = (UInt8 *)CFDataGetBytePtr(m_DataRed1);
double lenghtSource = CFDataGetLength(m_DataRed1);
NSLog(@"lenght : %f",lenghtSource);

int bytesPerPixel_ = CGImageGetBitsPerPixel(imgSource)/8;
size_t bytesPerRow = CGImageGetBytesPerRow(imgSource);
NSLog(@"height = %f, width = %f, bytesperPixel = %d",myheight,mywidth,bytesPerPixel_);
for(int x = 0; x < mywidth; x++)
{
    for(int y = 0; y < myheight; y++)
    {
        int pixelStartIndex = 4*((bytesPerRow*x)+y);
        if (pixelStartIndex <= lenghtSource) {
            UInt8 alphaVal = dataOrignal[pixelStartIndex];
            UInt8 redVal = dataOrignal[pixelStartIndex + 1];
            UInt8 greenVal = dataOrignal[pixelStartIndex + 2];
            UInt8 blueVal = dataOrignal[pixelStartIndex + 3];

            if(redVal == 236 || blueVal == 236 || greenVal == 236)
            {
                dataOrignal[pixelStartIndex + 1] = 205;
                dataOrignal[pixelStartIndex +2] = 25;
                dataOrignal[pixelStartIndex+3]= 55;
                NSLog(@"x %d, y = %d, index = %d", x, y,pixelStartIndex);
            }

        }
    }                

}

NSUInteger width = CGImageGetWidth(imgSource); //202
NSUInteger height = CGImageGetHeight(imgSource);//173
size_t bitsPerComponent = CGImageGetBitsPerComponent(imgSource);
size_t bitsPerPixel = CGImageGetBitsPerPixel(imgSource);




NSLog(@"the width = %u and height=%u of the image is ",width,height );
NSLog(@"the bits per component is %zd", bitsPerComponent);
NSLog(@"the bits per pixel is %zd", bitsPerPixel);
NSLog(@"the bytes per row is %zd" , bytesPerRow);

CGColorSpaceRef colorspace = CGImageGetColorSpace(imgSource);
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imgSource);
CFDataRef newData = CFDataCreate(NULL, dataOrignal, lenghtSource);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(newData);

CGContextRef context = CGBitmapContextCreate(newData, width, height, bitsPerComponent, bytesPerRow, colorspace, bitmapInfo);
CGPoint point = CGContextGetTextPosition(context);
NSInteger xx =  point.x;

// point.y;

NSLog(@"this is the value of x axis %d",xx);

CGImageRef newImg = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, true, kCGRenderingIntentDefault);





UIImage *newImage1 = [UIImage imageWithCGImage:newImg];
self.ImageView.image = newImage1;

今、ピーク値の x 値と y 値を見つけたいので、どうすればそれを見つけることができますか?

4

1 に答える 1