iphoneの最近のブログ記事

1、Frameworkを追加
#import <AssetsLibrary/AssetsLibrary.h>
#import <ImageIO/ImageIO.h>

2、サンプルコード
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {

    [picker dismissModalViewControllerAnimated:NO];

    // カメラロールからiPhoneカメラで撮った場合、GPSなど取得可能
    NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibrary *lib = [[[ALAssetsLibrary alloc] init] autorelease];
    NSLog(@">>>>>> %@", url);
   
    [lib assetForURL:url
        resultBlock:^(ALAsset *asset){
            ALAssetRepresentation *representation = [asset defaultRepresentation];
            NSUInteger size = [representation size];
            uint8_t *buff = (uint8_t *)malloc(sizeof(uint8_t)*size);
            if(buff != nil){
                NSError *error = nil;
                NSUInteger bytesRead = [representation getBytes:buff fromOffset:0 length:size error:&error];
                if (bytesRead && !error) {
                    NSData *photo = [NSData dataWithBytesNoCopy:buff length:bytesRead freeWhenDone:YES];


                    CGImageSourceRef cgImage = CGImageSourceCreateWithData((CFDataRef)photo, nil);
                    NSMutableDictionary *imageMetadata = (NSMutableDictionary *)CGImageSourceCopyPropertiesAtIndex(cgImage, 0, nil);
                    if (imageMetadata) {
                        NSLog(@"%@", [imageMetadata description]);
                       // GPSはこんなかんじで取得
                        if ([imageMetadata valueForKey:@"{GPS}"]) {
                              CLLocationDegrees lat = (CLLocationDegrees)[[[imageMetadata objectForKey:@"{GPS}"] objectForKey:@"Latitude"] doubleValue];
                              CLLocationDegrees lng = (CLLocationDegrees)[[[imageMetadata objectForKey:@"{GPS}"] objectForKey:@"Longitude"] doubleValue];
                        }

                    } else {
                        NSLog(@"no metadata");
                    }
                    CFRelease(cgImage);
                }
                if (error) {
                    NSLog(@"error:%@", error);
                    [error release];
                    free(buff);
                }
            }
        }
        failureBlock:^(NSError *error){
                 NSLog(@"error:%@", error);
             }];

}
--- どこかで、---
queue = [[NSOperationQueue alloc] init];
---

ASIHTTPRequest で setDelegate:self をしていた場合、
かつqueueを利用する場合、
queueのオペレーションから requestを引っぱり、
queueをリリースする。
queue以下にdelegateがあるオブジェクトがあるときは、
末端までたどり、何らかの方法でキャンセルする。
queueは最小単位で使う方がよい。
元のオブジェクトをリリースしたらちゃんと末端も処理できるような感じで、
かつ、わかりやすくやならないと、いけないみたい。(反省、、、)
ベースのqueue管理を作るより、最小単位で組み込みその大本をリリースするが良さげ。


 if (queue) {
        for (ASIHTTPRequest *request in queue.operations) {
            [request clearDelegatesAndCancel];
        
        }
        [queue cancelAllOperations];
       // 例 [queue waitUntilAllOperationsAreFinished];
       // waitUntilAllOperationsAreFinished だと処理が終わるまで待つ。

        [queue release];
        queue = nil;
}

iphone convertToUTC メモ

- (NSDate *)convertToUTC:(NSDate*)sourceDate {
    NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
    NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];

    NSInteger currentGMTOffset = [currentTimeZone secondsFromGMTForDate:sourceDate];
    NSInteger gmtOffset = [utcTimeZone secondsFromGMTForDate:sourceDate];
    NSTimeInterval gmtInterval = gmtOffset - currentGMTOffset;

    NSDate *destinationDate = [[NSDate alloc] initWithTimeInterval:gmtInterval sinceDate:sourceDate];
    return destinationDate;
}

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
[request setCachePolicy:ASIOnlyLoadIfNotCachedCachePolicy];

ASIDownloadCache *cache = [[ASIDownloadCache alloc] init];
[cache setStoragePath:[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequestCache"]];
[cache removeCachedDataForRequest:request];

これで行けた。
ASIDownloadCacheのremoveCachedDataForRequestを使う。
storagePathを指定してあげないと行けないようだったので上記のNSSearchで取得。
これは、ASIDownloadCache.mを眺めてたら分かった。



まえのブログの続き、
xcodeで使う時。

project setting -> build で、
Open Linker Flags を

$(SRCROOT)/opencv_device/lib/libopencv_core.a $(SRCROOT)/opencv_device/lib/libopencv_legacy.a $(SRCROOT)/opencv_device/lib/libopencv_imgproc.a $(SRCROOT)/opencv_device/lib/libopencv_objdetect.a -lstdc++ -lz

と設定、
SRCROOT
コンパイルしたopencv_*を置いておく。

あと、
Search Paths のHeader Search Path と Library Search Path に
simulator と device の include と lib のパスを記述。

開発環境の準備完了。

iphone + opencv をmacへ

久々ブログ。
burtn風に写真がとれるようになったので、
撮った写真のエフェクト加工にはいります。

備忘録メモ、

参照サイト:
http://niw.at/articles/2009/03/14/using-opencv-on-iphone/ja
http://bassabsoft.blogspot.com/2010/03/opencv-with-iphone-2.html

もちろんxcodeも入れておきます。

$ sudo port selfupdate
checksumエラーは selfupdate を使う。
apt系のapt-get updateと同等。

cmake をインストール、
$ sudo port install cmake
しておく。

あとは、上記の参照サイトの手順で、
$ git clone git://github.com/niw/iphone_opencv_test.git
twitterではたらくniwaさんのgitからダウンロード
niwaさんのブログ git git://になっていますが、git cloneが正解です。
git も入れておく必要がある。

http://www.atinfinity.info/wiki/index.php?OpenCV%2FUsing%20OpenCV%202.2%20on%20iOS%20SDK%204.2

に ios sdk 4.2 + opencv-2.2.0のがあった。



このアーカイブについて

このページには、過去に書かれたブログ記事のうちiphoneカテゴリに属しているものが含まれています。

前のカテゴリはGOOGLEです。

次のカテゴリはMY DEBIANです。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。