2014-04-29 1 views
3

큰 이미지가있는 이미지 처리 iOS 앱을 만들고 있습니다 (예 : 크기는 2000x2000). 이미지의 한 부분이 다른 색상을 사용한다는 것을 제외하고 이미지가 완전히 검은 색이라고 가정합니다 (해당 영역의 크기가 200x200이라고 가정하십시오).iOS의 이미지에서 특정 색상의 영역을 어떻게 찾을 수 있습니까?

SI는 다른 색으로 칠해진 영역의 시작과 끝 위치를 계산하려고합니다. 이것을 어떻게 할 수 있습니까?

+0

opencv를 사용하십시오. http://opencv.org/ – iphonic

+1

아마도 도움이 될 것입니다. OpenCV 사용. http://stackoverflow.com/questions/8667818/opencv-c-obj-c-detecting-a-sheet-of-paper-square-detection –

+0

[this] (https://github.com/BradLarson)에 체크 할 수 있습니다./GPUI 이미지). – mownier

답변

0

다음은 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); 
} 
관련 문제