Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ endif (UNIX AND NOT APPLE)

if (APPLE)
add_subdirectory (opencv)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (OpenCV_FOUND)
set(useOpenCV "true")
else()
if(NOT ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"))
message (ERROR "clang is required to build libcammacos")
endif()
set(useOpenCV "false")
add_subdirectory (macos)
endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
endif()
endif (APPLE)

if (NOT UNIX)
message (ERROR "This package only builds on Unix platforms")
endif (NOT UNIX)

install_files(/lua/camera init.lua)

SET(src)
SET(luasrc init.lua)
SET(luasrc "${CMAKE_BINARY_DIR}/init.lua")
configure_file(init.lua.in "${luasrc}")
install_files(/lua/camera "${luasrc}")
ADD_TORCH_PACKAGE(camera "${src}" "${luasrc}" "Image Processing")
7 changes: 5 additions & 2 deletions init.lua → init.lua.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ require 'xlua'
----------------------------------
-- load camera driver based on OS
----------------------------------

useOpenCV = @useOpenCV@

if useOpenCV then
if not xlua.require 'camopencv' then
xlua.error('failed to load camopencv wrapper: verify that camopencv is installed')
Expand All @@ -17,8 +20,8 @@ elseif sys.OS == 'linux' then
xlua.error('failed to load video4linux wrapper: verify that you have v4l2 libs')
end
elseif sys.OS == 'macos' then
if not xlua.require 'camopencv' then
xlua.error('failed to load camopencv wrapper: verify that camopencv is installed')
if not xlua.require 'cammacos' then
xlua.error('failed to load cammacos wrapper: verify that cammacos is installed')
end
else
xlua.error('no camera driver available for your OS, sorry :-(')
Expand Down
26 changes: 13 additions & 13 deletions macos/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
#import <AVFoundation/AVFoundation.h>

#define error(...) fprintf(stderr, __VA_ARGS__)
#define console(...) (!g_quiet && printf(__VA_ARGS__))
Expand All @@ -12,34 +12,34 @@
BOOL g_verbose = NO;
BOOL g_quiet = NO;

@interface ImageSnap : NSObject {
@interface ImageSnap : NSObject<AVCaptureVideoDataOutputSampleBufferDelegate> {

QTCaptureSession *mCaptureSession;
QTCaptureDeviceInput *mCaptureDeviceInput;
QTCaptureDecompressedVideoOutput *mCaptureDecompressedVideoOutput;
AVCaptureSession *mCaptureSession;
AVCaptureDeviceInput *mCaptureDeviceInput;
AVCaptureVideoDataOutput *mCaptureDecompressedVideoOutput;
CVImageBufferRef mCurrentImageBuffer;
}

/**
* Returns all attached QTCaptureDevice objects that have video.
* This includes video-only devices (QTMediaTypeVideo) and
* audio/video devices (QTMediaTypeMuxed).
* Returns all attached AVCaptureDevice objects that have video.
* This includes video-only devices (AVMediaTypeVideo) and
* audio/video devices (AVMediaTypeMuxed).
*
* @return autoreleased array of video devices
*/
+(NSArray *)videoDevices;

/**
* Returns the default QTCaptureDevice object for video
* Returns the default AVCaptureDevice object for video
* or nil if none is found.
*/
+(QTCaptureDevice *)defaultVideoDevice;
+(AVCaptureDevice *)defaultVideoDevice;

/**
* Returns the QTCaptureDevice with the given name
* Returns the AVCaptureDevice with the given name
* or nil if the device cannot be found.
*/
+(QTCaptureDevice *)deviceNamed:(NSString *)name;
+(AVCaptureDevice *)deviceNamed:(NSString *)name;

/**
* Writes an NSImage to disk, formatting it according
Expand All @@ -58,7 +58,7 @@ BOOL g_quiet = NO;
-(id)init;
-(void)dealloc;

-(BOOL)startSession:(QTCaptureDevice *)device withWidth:(unsigned int)width withHeight:(unsigned int)height;
-(BOOL)startSession:(AVCaptureDevice *)device withWidth:(unsigned int)width withHeight:(unsigned int)height;
-(CIImage *)snapshot;
-(void)stopSession;

Expand Down
Loading