我在iOS 3.1.3 iPhone上测试我的iPhone应用程序.我使用以下方法选择/捕获图像UIImagePickerController:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self.navigationController presentModalViewController:imagePicker animated:YES];
[imagePicker release];
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = self.image;
[self.navigationController dismissModalViewControllerAnimated:YES];
submitButton.enabled = YES;
}
Run Code Online (Sandbox Code Playgroud)
然后我在某个时候使用ASI类将它发送到我的Web服务器:
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://example.com/myscript.php"]];
[request setDelegate:self];
[request setStringEncoding:NSUTF8StringEncoding];
[request setShouldContinueWhenAppEntersBackground:YES];
//other post keys/values
[request setFile:UIImageJPEGRepresentation(self.image, 100.0f) withFileName:[NSString stringWithFormat:@"%d.jpg", [[NSDate date] timeIntervalSinceNow]] andContentType:@"image/jpg" forKey:@"imageFile"];
[request startAsynchronous];
Run Code Online (Sandbox Code Playgroud)
问题:当我用iphone拍照同时保持它的风景时,图像会上传到服务器并按照你的预期进行查看.当拍摄手机拍照时,图像会被上传并在旋转90度时被观看.
我的应用程序设置为仅在纵向模式下工作(颠倒和常规).
如何在上传后使图像始终显示正确的方向?
UIImageView中显示的图像看起来是正确的(在拍照后直接显示),但在服务器上查看则另有说明.
我有一个UIImage,它是从iPhone相机拍摄的照片,现在我希望将UIImage转换为cv :: Mat(OpenCV).我使用以下代码行来完成此任务:
-(cv::Mat)CVMat
{
CGColorSpaceRef colorSpace = CGImageGetColorSpace(self.CGImage);
CGFloat cols = self.size.width;
CGFloat rows = self.size.height;
cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to backing data
cols, // Width of bitmap
rows, // Height of bitmap
8, // Bits per component
cvMat.step[0], // Bytes per row
colorSpace, // Colorspace
kCGImageAlphaNoneSkipLast |
kCGBitmapByteOrderDefault); // Bitmap info flags
CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), self.CGImage);
CGContextRelease(contextRef);
return cvMat;
}
Run Code Online (Sandbox Code Playgroud)
此代码适用于横向模式下的UIImage,但当我使用与从纵向模式拍摄的图像相同的代码时,图像会向右旋转90度.
我是iOS和Objective C的新手,因此我无法弄清楚出了什么问题. …
如果图像是UIImage,我们可以在xcode中以调试模式查看图像,但我不能用于cv :: mat图像,这是正常的,所以无论如何还是我们可以添加到xcode中的任何附加工具来显示(或者查看cv :: mat图像的调试模式下的图像?
我在 mac 10.7.5 上尝试使用 XCode 4.6.2 中的 OpenCV 库。我正在关注本教程http://sadeepj.blogspot.co.uk/2012/03/installing-and-configuring-opencv-to.html
所以我已经下载了我在终端中编写的 cmake 和 OpenCV2.3.1:
tar xvf OpenCV-2.3.1a.tar.bz2
cd OpenCV-2.3.1
mkdir build
cd build
cmake -G "Unix Makefiles" ..
Run Code Online (Sandbox Code Playgroud)
除了在Unix Makefiles命令中,它说的一切都有效CMake Error: Could not create named generator Unix Makefiles..
任何人都知道为什么会发生这种情况,或者可能有另一种方法可以让 OpenCV 在 Xcode 中顺利运行?