Skip to content

Commit

Permalink
added single camera demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gilshohet committed Mar 17, 2017
1 parent e097d72 commit 953e6c3
Show file tree
Hide file tree
Showing 6 changed files with 11,441 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Ignore everything by default.
*.*
*/CMakeFiles

#Don't ignore the .gitignore (duh)
!.gitignore
Expand All @@ -14,4 +15,4 @@

#Do not ignore CMakeLists.txt and Makefiles for the samples
!CMakeLists.txt
!Makefile
!Makefile
8 changes: 8 additions & 0 deletions camera/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Don't ignore the .gitignore (duh)
!.gitignore

#Ignore the makefile here since it's generated by CMake
*Makefile*

#Ignore executables
singleCameraDemo
22 changes: 22 additions & 0 deletions camera/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required (VERSION 2.8)

project(cameraDemo)

# required packages and directories (OpenCV + XIMEA API)
find_package(OpenCV REQUIRED)
find_library(LIBM3API_LIB NAMES libm3api.so)

include_directories(${OpenCV_INCLUDE_DIRS})

# problem with opencv + cuda on tegra, this setting required
# must explicitly build with -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF the first time
message(STATUS "CUDA_USE_STATIC_CUDA_RUNTIME " ${CUDA_USE_STATIC_CUDA_RUNTIME})

# executables
add_executable(singleCameraDemo
singleCameraDemo.cpp
xiApiPlusOcv.hpp
xiApiPlusOcv.cpp)

# link libraries
target_link_libraries(singleCameraDemo ${OpenCV_LIBS} ${LIBM3API_LIB})
61 changes: 61 additions & 0 deletions camera/singleCameraDemo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Program opens first camera, captures 100 images, displays them, and
* writes the images to jpg file in images/ directory.
*
* Based on the xiApiPlusOcvExample.cpp file from XIMEA.
**/
#include <iostream>
#include <sstream>
#include "xiApiPlusOcv.hpp"
#include "opencv2/highgui/highgui.hpp"

int nImages = 100;

int main(int argc, char* argv[])
{
try
{
// set up camera
xiAPIplusCameraOcv cam;
cam.OpenFirst(); // open the camera
cam.SetExposureTime(10000); // exposure time 10 ms
cam.StartAcquisition(); // start aquiring images
XI_IMG_FORMAT format = cam.GetImageDataFormat(); // image format

cv::Mat cap;
for (int i = 0; i < nImages; i++)
{
cap = cam.GetNextImageOcvMat(); // capture image

// normalize image if needed (depending on format)
if (format == XI_RAW16 || format == XI_MONO16)
{
cv::normalize(cap, cap, 0, 65536, cv::NORM_MINMAX,
-1, cv::Mat());
}

// display
cv::imshow("image", cap);
cv::waitKey(20);

// write jpeg
std::ostringstream name;
name << "images/";
if (i < 10) name << "0";
name << i << ".jpg";
std::cout << "Writing image " << name.str() << std::endl;
cv::imwrite(name.str(), cap);
}

// shut down the camera
cam.StopAcquisition();
cam.Close();
}
catch(xiAPIplus_Exception& exp)
{
std::cerr << "Error:" << std::endl;
exp.PrintError();
cv::waitKey(2000);
}
return 0;
}
Loading

0 comments on commit 953e6c3

Please sign in to comment.