1
A
回答
2
從概念上講,所有你需要做的是循環通過手機拍攝的照片的像素數據,並且對於不在某個綠色範圍內的每個像素,將該像素複製到背景圖像上的相同位置。
這裏是一個例子,我從keremic的回答到another stackoverflow問題的修改。 注意:這是未經測試,只是爲了給你的技術的思想,將工作
//Get data into C array
CGImageRef image = [UIImage CGImage];
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel_ * width;
NSUInteger bitsPerComponent = 8;
unsigned char *data = malloc(height * width * bytesPerPixel);
// you will need to copy your background image into resulting_image_data.
// which I am not showing here
unsigned char *resulting_image_data = malloc(height * width * bytesPerPixel);
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height));
CGContextRelease(context);
//loop through each pixel
for(int row = 0; row < height; row++){
for(int col = 0; col < width*bytesPerPixel; col=col+4){
red = data[col];
green = data[col + 1];
blue = data[col + 2];
alpha = data[col + 3];
// if the pixel is within a shade of green
if(!(green > 250 && red < 10 && blue < 10)){
//copy them over to the background image
resulting_image_data[row*col] = red;
resulting_image_data[row*col+1] = green;
resulting_image_data[row*col+2] = blue;
resulting_image_data[row*col+3] = alpha;
}
}
}
//covert resulting_image_data into a UIImage
0
看看編譯OpenCV for iPhone - 不是一件容易的事,但它可以讓你訪問一個真正偉大的圖像處理工具的整個庫。
我正在使用openCV開發我現在正在開發的應用程序(並非所有與您不同的應用程序) - 對於您要做的事情,openCV將是一個很好的解決方案,儘管它需要一點點學習等等。一旦你有OpenCV的工作,去除綠色的實際任務不應該太難。
編輯:這個鏈接將是一個有用的資源,如果你決定使用OpenCV的:Compiling OpenCV for iOS
相關問題
- 1. iPhone App Store綠色按鈕
- 2. 實況視頻綠色屏幕效果(無綠屏)
- 3. 需要閃爍屏幕綠色5秒
- 4. 使用nsimage作爲「綠色屏幕」
- 5. 將Iphone屏幕轉換爲Ipad屏幕
- 6. Iphone屏幕黑色啓動
- 7. 綠色或白色的屏幕,處理+超高動力學
- 8. EarlGrey推出帶黑色屏幕的APP
- 9. 綠屏/色度鍵iOS
- 10. 替換Android屏幕鎖
- 11. FragmentTransaction替換整個屏幕
- 12. 替換屏幕上的控件
- 13. 綠色陰影同時拍攝屏幕拍攝的視圖
- 14. OpenCV2.2 cvCaptureFromCAM問題...只返回綠色屏幕。 (羅技C260相機)
- 15. 綠色屏幕當調用Windows Phone上PhotoCaptureDevice API 8
- 16. 在ffmpeg中製作綠色屏幕背景
- 17. 訪問前置攝像頭「綠色屏幕」?
- 18. 通過Janus和Gstreamer獲取視頻流中的綠色屏幕
- 19. iphone 3gs cameraoverylay只顯示白色屏幕
- 20. 白色屏幕上模擬iPhone的Xcode
- 21. 顯示白色/黑色屏幕而不是啓動屏幕
- 22. 製作iphone app .xib文件適合iphone 5 4英寸屏幕
- 23. iPhone 5屏幕截圖沒有在iPhone 5 App Store上顯示
- 24. Iphone屏幕鎖
- 25. ios灰色屏幕
- 26. 藍綠色轉換策略
- 27. FFMPEG:用於圖像/視頻的色度鍵/綠色屏幕過濾器
- 28. iPhone屏幕截圖轉換UIImageView
- 29. iPhone切換屏幕在xcode 4.2
- 30. iOS 9的黑色屏幕
如果你做這種方式,那麼你可以通過在周圍像素找你循環通過它做一些改進。如果大部分周圍的像素都是綠色的,但當前的像素不是綠色的,它可能是綠色屏幕的一部分(但由於任何原因像素看起來不綠)。此外,使用類似的技術,你可能想要平滑任何檢測到的綠色屏幕部件的邊緣 - 它可能看起來更好一些:) – 2011-05-14 04:08:20
+1喬丹。好主意! – 2011-05-14 19:39:06