다음은 CPU가 UIImage에서 픽셀 값을 가져올 수있는 간단한 방법입니다. 단계는
- 는 화소
- (버퍼에 픽셀을 기록) 컨텍스트로 화상을 그리는 배킹 스토어
- 로 버퍼를 이용하여 비트 맵 메모리 콘텍스트를 생성
- 하는 버퍼를 할당 할 수 있습니다
- 무료 버퍼의 픽셀 버퍼 및 관련 자원
검토
- (void)processImage:(UIImage *)input
{
int width = input.size.width;
int height = input.size.height;
// allocate the pixel buffer
uint32_t *pixelBuffer = calloc(width * height, sizeof(uint32_t));
// create a context with RGBA pixels
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixelBuffer, width, height, 8, width * sizeof(uint32_t), colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast);
// invert the y-axis, so that increasing y is down
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0, -height);
// draw the image into the pixel buffer
UIGraphicsPushContext(context);
[input drawAtPoint:CGPointZero];
UIGraphicsPopContext();
// scan the image
int x, y;
uint8_t r, g, b, a;
uint8_t *pixel = (uint8_t *)pixelBuffer;
for (y = 0; y < height; y++)
for (x = 0; x < height; x++)
{
r = pixel[0];
g = pixel[1];
b = pixel[2];
a = pixel[3];
// do something with the pixel value here
pixel += 4;
}
// release the resources
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
free(pixelBuffer);
}
opencv를 사용하십시오. http://opencv.org/ – iphonic
아마도 도움이 될 것입니다. OpenCV 사용. http://stackoverflow.com/questions/8667818/opencv-c-obj-c-detecting-a-sheet-of-paper-square-detection –
[this] (https://github.com/BradLarson)에 체크 할 수 있습니다./GPUI 이미지). – mownier