Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
8efb84b5
Commit
8efb84b5
authored
Aug 20, 2012
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added ios camera support in highgui. turned on optimization in opencv2.framework (ticket #2232)
parent
c26d543e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
334 additions
and
1 deletion
+334
-1
iOS.cmake
ios/cmake/Modules/Platform/iOS.cmake
+2
-0
core.hpp
modules/core/include/opencv2/core/core.hpp
+1
-1
CMakeLists.txt
modules/highgui/CMakeLists.txt
+6
-0
cap_ios.h
modules/highgui/include/opencv2/highgui/cap_ios.h
+160
-0
cap_ios_abstract_camera.mm
modules/highgui/src/cap_ios_abstract_camera.mm
+0
-0
cap_ios_photo_camera.mm
modules/highgui/src/cap_ios_photo_camera.mm
+165
-0
cap_ios_video_camera.mm
modules/highgui/src/cap_ios_video_camera.mm
+0
-0
No files found.
ios/cmake/Modules/Platform/iOS.cmake
View file @
8efb84b5
...
...
@@ -42,6 +42,8 @@ set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
set
(
CMAKE_C_FLAGS
""
)
set
(
CMAKE_CXX_FLAGS
"-headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden"
)
set
(
CMAKE_CXX_FLAGS_RELEASE
"-O3 -fomit-frame-pointer"
)
if
(
HAVE_FLAG_SEARCH_PATHS_FIRST
)
set
(
CMAKE_C_LINK_FLAGS
"-Wl,-search_paths_first
${
CMAKE_C_LINK_FLAGS
}
"
)
set
(
CMAKE_CXX_LINK_FLAGS
"-Wl,-search_paths_first
${
CMAKE_CXX_LINK_FLAGS
}
"
)
...
...
modules/core/include/opencv2/core/core.hpp
View file @
8efb84b5
...
...
@@ -440,7 +440,7 @@ template<typename _Tp, int m, int n> class CV_EXPORTS Matx
{
public
:
typedef
_Tp
value_type
;
typedef
Matx
<
_Tp
,
MIN
(
m
,
n
),
1
>
diag_type
;
typedef
Matx
<
_Tp
,
(
m
<
n
?
m
:
n
),
1
>
diag_type
;
typedef
Matx
<
_Tp
,
m
,
n
>
mat_type
;
enum
{
depth
=
DataDepth
<
_Tp
>::
value
,
rows
=
m
,
cols
=
n
,
channels
=
rows
*
cols
,
type
=
CV_MAKETYPE
(
depth
,
channels
)
};
...
...
modules/highgui/CMakeLists.txt
View file @
8efb84b5
...
...
@@ -193,6 +193,12 @@ elseif(APPLE)
endif
()
endif
()
if
(
IOS
)
add_definitions
(
-DHAVE_IOS=1
)
list
(
APPEND highgui_srcs src/cap_ios_abstract_camera.mm src/cap_ios_photo_camera.mm src/cap_ios_video_camera.mm
)
list
(
APPEND HIGHGUI_LIBRARIES
"-framework Accelerate"
"-framework AVFoundation"
"-framework CoreGraphics"
"-framework CoreImage"
"-framework CoreMedia"
"-framework CoreVideo"
"-framework QuartzCore"
"-framework AssetsLibrary"
)
endif
()
if
(
WIN32
)
link_directories
(
"
${
OpenCV_SOURCE_DIR
}
/3rdparty/lib"
)
# for ffmpeg wrapper only
include_directories
(
AFTER SYSTEM
"
${
OpenCV_SOURCE_DIR
}
/3rdparty/include"
)
# for directshow in VS2005 and multi-monitor support on MinGW
...
...
modules/highgui/include/opencv2/highgui/cap_ios.h
0 → 100644
View file @
8efb84b5
/*
* cap_ios.h
* For iOS video I/O
* by Eduard Feicho on 29/07/12
* Copyright 2012. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#import <UIKit/UIKit.h>
#import <Accelerate/Accelerate.h>
#import <AVFoundation/AVFoundation.h>
#import <ImageIO/ImageIO.h>
#include "opencv2/core/core.hpp"
/////////////////////////////////////// CvAbstractCamera /////////////////////////////////////
@class
CvAbstractCamera
;
@interface
CvAbstractCamera
:
NSObject
{
AVCaptureSession
*
captureSession
;
AVCaptureConnection
*
videoCaptureConnection
;
AVCaptureVideoPreviewLayer
*
captureVideoPreviewLayer
;
UIDeviceOrientation
currentDeviceOrientation
;
BOOL
cameraAvailable
;
BOOL
captureSessionLoaded
;
BOOL
running
;
BOOL
useAVCaptureVideoPreviewLayer
;
AVCaptureDevicePosition
defaultAVCaptureDevicePosition
;
AVCaptureVideoOrientation
defaultAVCaptureVideoOrientation
;
NSString
*
const
defaultAVCaptureSessionPreset
;
int
defaultFPS
;
UIView
*
parentView
;
int
imageWidth
;
int
imageHeight
;
}
@property
(
nonatomic
,
retain
)
AVCaptureSession
*
captureSession
;
@property
(
nonatomic
,
retain
)
AVCaptureConnection
*
videoCaptureConnection
;
@property
(
nonatomic
,
readonly
)
BOOL
running
;
@property
(
nonatomic
,
readonly
)
BOOL
captureSessionLoaded
;
@property
(
nonatomic
,
assign
)
int
defaultFPS
;
@property
(
nonatomic
,
assign
)
AVCaptureDevicePosition
defaultAVCaptureDevicePosition
;
@property
(
nonatomic
,
assign
)
AVCaptureVideoOrientation
defaultAVCaptureVideoOrientation
;
@property
(
nonatomic
,
assign
)
BOOL
useAVCaptureVideoPreviewLayer
;
@property
(
nonatomic
,
strong
)
NSString
*
const
defaultAVCaptureSessionPreset
;
@property
(
nonatomic
,
assign
)
int
imageWidth
;
@property
(
nonatomic
,
assign
)
int
imageHeight
;
@property
(
nonatomic
,
retain
)
UIView
*
parentView
;
-
(
void
)
pause
;
-
(
void
)
start
;
-
(
void
)
stop
;
-
(
void
)
switchCameras
;
-
(
id
)
initWithParentView
:(
UIView
*
)
parent
;
-
(
void
)
createCaptureOutput
;
-
(
void
)
createVideoPreviewLayer
;
-
(
void
)
updateOrientation
;
@end
///////////////////////////////// CvVideoCamera ///////////////////////////////////////////
@class
CvVideoCamera
;
@protocol
CvVideoCameraDelegate
<
NSObject
>
#ifdef __cplusplus
// delegate method for processing image frames
-
(
void
)
processImage
:
(
cv
::
Mat
&
)
image
;
#endif
@end
@interface
CvVideoCamera
:
CvAbstractCamera
<
AVCaptureVideoDataOutputSampleBufferDelegate
>
{
AVCaptureVideoDataOutput
*
videoDataOutput
;
dispatch_queue_t
videoDataOutputQueue
;
CALayer
*
customPreviewLayer
;
BOOL
grayscaleMode
;
BOOL
recordVideo
;
AVAssetWriterInput
*
recordAssetWriterInput
;
AVAssetWriterInputPixelBufferAdaptor
*
recordPixelBufferAdaptor
;
AVAssetWriter
*
recordAssetWriter
;
}
@property
(
nonatomic
,
assign
)
id
<
CvVideoCameraDelegate
>
delegate
;
@property
(
nonatomic
,
assign
)
BOOL
grayscaleMode
;
@property
(
nonatomic
,
assign
)
BOOL
recordVideo
;
@property
(
nonatomic
,
retain
)
AVAssetWriterInput
*
recordAssetWriterInput
;
@property
(
nonatomic
,
retain
)
AVAssetWriterInputPixelBufferAdaptor
*
recordPixelBufferAdaptor
;
@property
(
nonatomic
,
retain
)
AVAssetWriter
*
recordAssetWriter
;
-
(
void
)
adjustLayoutToInterfaceOrientation
:(
UIInterfaceOrientation
)
interfaceOrientation
;
-
(
void
)
layoutPreviewLayer
;
-
(
void
)
saveVideo
;
@end
///////////////////////////////// CvPhotoCamera ///////////////////////////////////////////
@class
CvPhotoCamera
;
@protocol
CvPhotoCameraDelegate
<
NSObject
>
-
(
void
)
photoCamera
:
(
CvPhotoCamera
*
)
photoCamera
capturedImage
:
(
UIImage
*
)
image
;
-
(
void
)
photoCameraCancel
:(
CvPhotoCamera
*
)
photoCamera
;
@end
@interface
CvPhotoCamera
:
CvAbstractCamera
{
AVCaptureStillImageOutput
*
stillImageOutput
;
}
@property
(
nonatomic
,
assign
)
id
<
CvPhotoCameraDelegate
>
delegate
;
-
(
void
)
takePicture
;
@end
modules/highgui/src/cap_ios_abstract_camera.mm
0 → 100644
View file @
8efb84b5
This diff is collapsed.
Click to expand it.
modules/highgui/src/cap_ios_photo_camera.mm
0 → 100644
View file @
8efb84b5
/*
* cap_ios_photo_camera.mm
* For iOS video I/O
* by Eduard Feicho on 29/07/12
* Copyright 2012. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#import "opencv2/highgui/cap_ios.h"
#include "precomp.hpp"
#pragma mark - Private Interface
@interface CvPhotoCamera ()
@property (nonatomic, retain) AVCaptureStillImageOutput* stillImageOutput;
@end
#pragma mark - Implementation
@implementation CvPhotoCamera
#pragma mark Public
@synthesize stillImageOutput;
@synthesize delegate;
#pragma mark - Public interface
- (void)takePicture
{
if (cameraAvailable == NO) {
return;
}
cameraAvailable = NO;
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:self.videoCaptureConnection
completionHandler:
^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
if (error == nil && imageSampleBuffer != NULL)
{
// TODO check
// NSNumber* imageOrientation = [UIImage cgImageOrientationForUIDeviceOrientation:currentDeviceOrientation];
// CMSetAttachment(imageSampleBuffer, kCGImagePropertyOrientation, imageOrientation, 1);
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
dispatch_async(dispatch_get_main_queue(), ^{
[self.captureSession stopRunning];
// Make sure we create objects on the main thread in the main context
UIImage* newImage = [UIImage imageWithData:jpegData];
//UIImageOrientation orientation = [newImage imageOrientation];
// TODO: only apply rotation, don't scale, since we can set this directly in the camera
/*
switch (orientation) {
case UIImageOrientationUp:
case UIImageOrientationDown:
newImage = [newImage imageWithAppliedRotationAndMaxSize:CGSizeMake(640.0, 480.0)];
break;
case UIImageOrientationLeft:
case UIImageOrientationRight:
newImage = [newImage imageWithMaxSize:CGSizeMake(640.0, 480.0)];
default:
break;
}
*/
// We have captured the image, we can allow the user to take another picture
cameraAvailable = YES;
NSLog(@"CvPhotoCamera captured image");
if (self.delegate) {
[self.delegate photoCamera:self capturedImage:newImage];
}
[self.captureSession startRunning];
});
}
}];
}
- (void)stop;
{
[super stop];
self.stillImageOutput = nil;
}
#pragma mark - Private Interface
- (void)createStillImageOutput;
{
// setup still image output with jpeg codec
self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
[self.stillImageOutput setOutputSettings:outputSettings];
[self.captureSession addOutput:self.stillImageOutput];
for (AVCaptureConnection *connection in self.stillImageOutput.connections) {
for (AVCaptureInputPort *port in [connection inputPorts]) {
if ([port.mediaType isEqual:AVMediaTypeVideo]) {
self.videoCaptureConnection = connection;
break;
}
}
if (self.videoCaptureConnection) {
break;
}
}
NSLog(@"[Camera] still image output created");
}
- (void)createCaptureOutput;
{
[self createStillImageOutput];
}
- (void)createCustomVideoPreview;
{
//do nothing, always use AVCaptureVideoPreviewLayer
}
@end
modules/highgui/src/cap_ios_video_camera.mm
0 → 100644
View file @
8efb84b5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment