diff --git a/CaroloCup-CameraPlayback.cpp b/CaroloCup-CameraPlayback.cpp index 87cc693..bc51651 100644 --- a/CaroloCup-CameraPlayback.cpp +++ b/CaroloCup-CameraPlayback.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,7 @@ using namespace std; // We add some of OpenDaVINCI's namespaces for the sake of readability. using namespace core; +using namespace core::base; using namespace core::data; using namespace core::data::image; using namespace core::io; @@ -111,25 +113,25 @@ int32_t main(int32_t argc, char **argv) { // Check if we could successfully attach to the shared memory. if (sharedImageMemory->isValid()) { - // Lock the memory region to get exclusive access. - sharedImageMemory->lock(); - { - if (image == NULL) { - // Create the IplImage header data and access the shared memory for the actual image data. - image = cvCreateImageHeader(cvSize(si.getWidth(), si.getHeight()), IPL_DEPTH_8U, si.getBytesPerPixel()); - - // Let the IplImage point to the shared memory containing the captured image. - image->imageData = static_cast(sharedImageMemory->getSharedMemory()); - } - - // Show the image using OpenCV. - cvShowImage("CaroloCup-CameraPlayback", image); - - // Let the image render before proceeding to the next image. - cvWaitKey(10); + // Using a shared lock to get exclusive access. + Lock l(sharedImageMemory); + + if (image == NULL) { + // Create the IplImage header data and access the shared memory for the actual image data. + image = cvCreateImageHeader(cvSize(si.getWidth(), si.getHeight()), IPL_DEPTH_8U, si.getBytesPerPixel()); + + // Let the IplImage point to the shared memory containing the captured image. + image->imageData = static_cast(sharedImageMemory->getSharedMemory()); } - // Release the memory region so that the player can provide the next raw image data. - sharedImageMemory->unlock(); + + // Show the image using OpenCV. + cvShowImage("CaroloCup-CameraPlayback", image); + + // Let the image render before proceeding to the next image. + char c = cvWaitKey(10); + + // Check if the user wants to stop the replay by pressing ESC. + if (static_cast(c) == 27) break; } } } diff --git a/Makefile b/Makefile index 0dd8c65..00c7b56 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ OBJS=$(subst .cpp,.o,$(SRCS)) # Make variables to create the Docker image. PRODUCT=carolocup-cameraplayback -VERSION=v1 +VERSION=v2 REPOSITORY=seresearch BUILDLOG=build.log