Skip to content

Commit

Permalink
* Fixed linux CloseStream bug that caused a delay of multiple seconds.
Browse files Browse the repository at this point in the history
* Added FPS support on Linux.
* Increased frame polling speed of Linux oc-gtk test program.
* Added support for brightness, contrast, autogain etc. properties.
  • Loading branch information
Niels Moseley committed Sep 28, 2017
2 parents 15986ee + 04d2a0e commit cb4be52
Show file tree
Hide file tree
Showing 486 changed files with 151,834 additions and 123 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ addons:
apt:
packages:
- libgtk-3-dev
- libturbojpeg
- libjpeg-turbo8-dev
- nasm

before_script:
- mkdir build
Expand Down
51 changes: 24 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
cmake_minimum_required(VERSION 3.1)
project (openpnp-capture)

set(POSITION_INDEPENDENT_CODE TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

# make CMAKE search the current cmake dir inside the
# current project
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
Expand Down Expand Up @@ -99,6 +103,16 @@ ELSEIF(APPLE)
add_subdirectory(mac/tests)

ELSEIF(UNIX)

# compile libjpeg-turbo for MJPEG decoding support
# right now, we need to disable SIMD because it
# causes a compile problem.. we need to fix this
# later...

set(ENABLE_SHARED OFF)
set(WITH_SIMD OFF)
add_subdirectory(linux/contrib/libjpeg-turbo-dev)

# set the platform identification string
add_definitions(-D__PLATFORM__="Linux ${COMPILERBITS}")

Expand All @@ -111,37 +125,20 @@ ELSEIF(UNIX)
linux/mjpeghelper.cpp
linux/yuvconverters.cpp)

# need pthreads for std::thread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# force include directories for libjpeg-turbo
include_directories(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/linux/contrib/libjpeg-turbo-dev")

# create our capture library
add_library(openpnp-capture SHARED ${SOURCE})

# add pthreads library
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(openpnp-capture Threads::Threads)

# this will force using the static lib, which will will eventually want to
# do for all dependencies so we don't have to distribute them with our .so
# find_library(TURBOJPEG_LIB NAMES turbojpeg.a turbojpeg)

# but libturbojpeg is not compiled with -fPIC which means it can't be static
# linked into a shared lib. So instead we will eventually have to build it
# ourselves with -fPIC and then we can use this to specify the location:
# ADD_LIBRARY(turbojpeg STATIC IMPORTED)
# SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION ../libjpegturbo/whatever/libjpegturbo.a)

# this lets us specify the full path of the turbojpeg library. this is required
# because of a bug in the library distribution that does not create the correct
# symlink. See https://github.com/OpenKinect/libfreenect2/issues/36
# Note: We should be able to specify this on the command line, as well, so we don't have
# to hardcode the path here.
ADD_LIBRARY(turbojpeg SHARED IMPORTED)
if(EXISTS "/usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0")
SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.1.0)
else()
SET_TARGET_PROPERTIES(turbojpeg PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0.0.0)
endif()

# add turbojpeg-static library
target_link_libraries(openpnp-capture turbojpeg-static)

target_link_libraries(openpnp-capture turbojpeg)

# add linux-specific test application
add_subdirectory(linux/tests)

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
![OpenPNP Logo](doc/logo_small.png)
![OpenPNP Logo](https://raw.githubusercontent.com/openpnp/openpnp-logo/develop/logo_small.png)

# openpnp-capture

OpenPnP Capture is a cross platform video capture library with a focus on machine vision. It's goals are:

Expand Down Expand Up @@ -59,15 +61,14 @@ OpenPnP Capture is a cross platform video capture library with a focus on machin

# TODO
* support for re-enumeration.
* support for setting/getting UVC properties on OSX.

# Building OpenPnP Capture

### Dependencies
* CMAKE 3.1 or better
* MAKE (osx, linux)
* Visual Studio 2013 + NMake or Ninja Build (windows)
* libjpeg-turbo, libjpeg-turbo8-dev (linux) -- will be merged into the project at a later time
* NASM for building libjpeg-turbo (linux)

### Build instructions (Windows)
Run the batch file 'bootstrap.bat' and choose the desired build system (VisualStudio/nmake or Ninja). Make sure the compiler (Visual Studio) is in the search path.
Expand All @@ -88,5 +89,5 @@ Run 'bootstrap_linux.sh'. Run make.

# Downloading Binaries

openpnp-capture is not yet ready for release, but you can download test binaries that are built automatically
openpnp-capture is still under development, but you can download releases that are built automatically
from https://github.com/openpnp/openpnp-capture/releases/latest.
21 changes: 20 additions & 1 deletion common/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ int32_t Context::openStream(CapDeviceID id, CapFormatID formatID)

if (!s->open(this, device, device->m_formats[formatID].width,
device->m_formats[formatID].height,
device->m_formats[formatID].fourcc))
device->m_formats[formatID].fourcc,
device->m_formats[formatID].fps))
{
LOG(LOG_ERR, "Could not open stream for device %s\n", device->m_name.c_str());
return -1;
Expand Down Expand Up @@ -267,6 +268,24 @@ uint32_t Context::getStreamFrameCount(int32_t streamID)
return stream->getFrameCount();
}

bool Context::setStreamFrameRate(int32_t streamID, uint32_t fps)
{
if (streamID < 0)
{
LOG(LOG_ERR, "setStreamFrameRate was called with a negative stream ID\n");
return 0;
}

Stream *stream = m_streams[streamID];
if (stream == nullptr)
{
LOG(LOG_ERR, "setStreamFrameRate was called with an unknown stream ID\n");
return false;
}

return stream->setFrameRate(fps);
}

#if 0
/** Lookup a stream by ID and return a pointer
to it if it exists. If it doesnt exist,
Expand Down
5 changes: 5 additions & 0 deletions common/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ class Context
/** returns the number of frames captured during the lifetime of the stream */
uint32_t getStreamFrameCount(int32_t streamID);

/** set the frame rate of a stream
returns false if the camera does not support the frame rate
*/
bool setStreamFrameRate(int32_t streamID, uint32_t fps);

/** Get the minimum and maximum settings for a property.
@param streamID the ID of the stream.
@param propertyID the ID of the property.
Expand Down
19 changes: 19 additions & 0 deletions common/libmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,25 @@ DLLPUBLIC uint32_t Cap_getStreamFrameCount(CapContext ctx, CapStream stream)
return 0;
}

#if 0

// not used for now..

DLLPUBLIC CapResult Cap_setFrameRate(CapContext ctx, CapStream stream, uint32_t fps)
{
if (ctx != 0)
{
Context *c = reinterpret_cast<Context*>(ctx);
if (!c->setStreamFrameRate(stream, fps))
{
return CAPRESULT_ERR;
}
return CAPRESULT_OK;
}
return CAPRESULT_ERR;
}
#endif

DLLPUBLIC CapResult Cap_getPropertyLimits(CapContext ctx, CapStream stream, CapPropertyID propID, int32_t *min, int32_t *max)
{
if (ctx != 0)
Expand Down
9 changes: 8 additions & 1 deletion common/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Stream
/** Open a capture stream to a device and request a specific (internal) stream format.
When succesfully opened, capturing starts immediately.
*/
virtual bool open(Context *owner, deviceInfo *device, uint32_t width, uint32_t height, uint32_t fourCC) = 0;
virtual bool open(Context *owner, deviceInfo *device, uint32_t width, uint32_t height,
uint32_t fourCC, uint32_t fps) = 0;

/** Close a capture stream */
virtual void close() {};
Expand All @@ -64,6 +65,12 @@ class Stream
*/
bool captureFrame(uint8_t *RGBbufferPtr, uint32_t RGBbufferBytes);

/** Set the frame rate of this stream.
Returns false if the camera does not support the desired
frame rate.
*/
virtual bool setFrameRate(uint32_t fps) = 0;

/** Returns true if the stream is open and capturing */
bool isOpen() const
{
Expand Down
14 changes: 10 additions & 4 deletions include/openpnp-capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ typedef uint32_t CapResult; ///< result defined by CAPRESULT_xxx
typedef uint32_t CapDeviceID; ///< unique device ID
typedef uint32_t CapFormatID; ///< format identifier 0 .. numFormats

#define CAPPROPID_EXPOSURE 1
#define CAPPROPID_FOCUS 2
#define CAPPROPID_ZOOM 3
// supported properties:
#define CAPPROPID_EXPOSURE 1
#define CAPPROPID_FOCUS 2
#define CAPPROPID_ZOOM 3
#define CAPPROPID_WHITEBALANCE 4
#define CAPPROPID_GAIN 5
#define CAPPROPID_BRIGHTNESS 6
#define CAPPROPID_CONTRAST 7
#define CAPPROPID_SATURATION 8
#define CAPPROPID_GAMMA 9
#define CAPPROPID_LAST 10

typedef uint32_t CapPropertyID; ///< property ID (exposure, zoom, focus etc.)

Expand Down Expand Up @@ -199,7 +206,6 @@ DLLPUBLIC CapResult Cap_closeStream(CapContext ctx, CapStream stream);
*/
DLLPUBLIC uint32_t Cap_isOpenStream(CapContext ctx, CapStream stream);


/**********************************************************************************
FRAME CAPTURING / INFO
**********************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions linux/contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The libjpeg-turbo-dev was downloaded from GITHUB:

https://github.com/libjpeg-turbo/libjpeg-turbo/tree/dev

on 28-9-2017.
Loading

0 comments on commit cb4be52

Please sign in to comment.