Normalize line endings and whitespace

This commit is contained in:
OpenCV Buildbot
2012-10-17 11:12:04 +04:00
committed by Andrey Kamaev
parent 0442bca235
commit 81f826db2b
1511 changed files with 258678 additions and 258624 deletions

View File

@@ -1,60 +1,60 @@
# ----------------------------------------------------------------------------
# CMake file for C samples. See root CMakeLists.txt
#
# ----------------------------------------------------------------------------
SET(OPENCV_C_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
ocv_check_dependencies(${OPENCV_C_SAMPLES_REQUIRED_DEPS})
if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
project(c_samples)
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
ocv_include_modules(${OPENCV_C_SAMPLES_REQUIRED_DEPS})
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO(OPENCV_DEFINE_C_EXAMPLE name srcs)
set(the_target "example_${name}")
add_executable(${the_target} ${srcs})
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_C_SAMPLES_REQUIRED_DEPS})
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "${name}"
PROJECT_LABEL "(EXAMPLE) ${name}")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples//c")
endif()
if(WIN32)
if(MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
install(TARGETS ${the_target}
RUNTIME DESTINATION "samples/c" COMPONENT main)
endif()
ENDMACRO()
file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
foreach(sample_filename ${cpp_samples})
get_filename_component(sample ${sample_filename} NAME_WE)
OPENCV_DEFINE_C_EXAMPLE(${sample} ${sample_filename})
endforeach()
endif()
if (INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
install(FILES ${C_SAMPLES}
DESTINATION share/OpenCV/samples/c
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif ()
# ----------------------------------------------------------------------------
# CMake file for C samples. See root CMakeLists.txt
#
# ----------------------------------------------------------------------------
SET(OPENCV_C_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc
opencv_highgui opencv_ml opencv_video opencv_objdetect opencv_photo opencv_nonfree
opencv_features2d opencv_calib3d opencv_legacy opencv_contrib)
ocv_check_dependencies(${OPENCV_C_SAMPLES_REQUIRED_DEPS})
if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND)
project(c_samples)
if(CMAKE_COMPILER_IS_GNUCXX AND NOT ENABLE_NOISY_WARNINGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function")
endif()
ocv_include_modules(${OPENCV_C_SAMPLES_REQUIRED_DEPS})
# ---------------------------------------------
# Define executable targets
# ---------------------------------------------
MACRO(OPENCV_DEFINE_C_EXAMPLE name srcs)
set(the_target "example_${name}")
add_executable(${the_target} ${srcs})
target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_C_SAMPLES_REQUIRED_DEPS})
set_target_properties(${the_target} PROPERTIES
OUTPUT_NAME "${name}"
PROJECT_LABEL "(EXAMPLE) ${name}")
if(ENABLE_SOLUTION_FOLDERS)
set_target_properties(${the_target} PROPERTIES FOLDER "samples//c")
endif()
if(WIN32)
if(MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${the_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
install(TARGETS ${the_target}
RUNTIME DESTINATION "samples/c" COMPONENT main)
endif()
ENDMACRO()
file(GLOB cpp_samples RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.c)
foreach(sample_filename ${cpp_samples})
get_filename_component(sample ${sample_filename} NAME_WE)
OPENCV_DEFINE_C_EXAMPLE(${sample} ${sample_filename})
endforeach()
endif()
if (INSTALL_C_EXAMPLES AND NOT WIN32)
file(GLOB C_SAMPLES *.c *.cpp *.jpg *.png *.data makefile.* build_all.sh *.dsp *.cmd )
install(FILES ${C_SAMPLES}
DESTINATION share/OpenCV/samples/c
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif ()

View File

@@ -1,413 +1,413 @@
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install, copy or use the software.
//
// Copyright (C) 2009, Farhad Dadgostar
// Intel Corporation and third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's 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.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "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 Intel Corporation or contributors 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.
//
//M*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
static void help(char **argv)
{
std::cout << "\nThis program demonstrates the contributed flesh detector CvAdaptiveSkinDetector which can be found in contrib.cpp\n"
<< "Usage: " << std::endl <<
argv[0] << " fileMask firstFrame lastFrame" << std::endl << std::endl <<
"Example: " << std::endl <<
argv[0] << " C:\\VideoSequences\\sample1\\right_view\\temp_%05d.jpg 0 1000" << std::endl <<
" iterates through temp_00000.jpg to temp_01000.jpg" << std::endl << std::endl <<
"If no parameter specified, this application will try to capture from the default Webcam." << std::endl <<
"Please note: Background should not contain large surfaces with skin tone." <<
"\n\n ESC will stop\n"
"Using OpenCV version %s\n" << CV_VERSION << "\n"
<< std::endl;
}
class ASDFrameHolder
{
private:
IplImage *image;
double timeStamp;
public:
ASDFrameHolder();
virtual ~ASDFrameHolder();
virtual void assignFrame(IplImage *sourceImage, double frameTime);
inline IplImage *getImage();
inline double getTimeStamp();
virtual void setImage(IplImage *sourceImage);
};
class ASDFrameSequencer
{
public:
virtual ~ASDFrameSequencer();
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
virtual void getFrameCaption(char *caption);
};
class ASDCVFrameSequencer : public ASDFrameSequencer
{
protected:
CvCapture *capture;
public:
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
};
class ASDFrameSequencerWebCam : public ASDCVFrameSequencer
{
public:
virtual bool open(int cameraIndex);
};
class ASDFrameSequencerVideoFile : public ASDCVFrameSequencer
{
public:
virtual bool open(const char *fileName);
};
class ASDFrameSequencerImageFile : public ASDFrameSequencer {
private:
char sFileNameMask[2048];
int nCurrentIndex, nStartIndex, nEndIndex;
public:
virtual void open(const char *fileNameMask, int startIndex, int endIndex);
virtual void getFrameCaption(char *caption);
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
};
//-------------------- ASDFrameHolder -----------------------//
ASDFrameHolder::ASDFrameHolder( )
{
image = NULL;
timeStamp = 0;
};
ASDFrameHolder::~ASDFrameHolder( )
{
cvReleaseImage(&image);
};
void ASDFrameHolder::assignFrame(IplImage *sourceImage, double frameTime)
{
if (image != NULL)
{
cvReleaseImage(&image);
image = NULL;
}
image = cvCloneImage(sourceImage);
timeStamp = frameTime;
};
IplImage *ASDFrameHolder::getImage()
{
return image;
};
double ASDFrameHolder::getTimeStamp()
{
return timeStamp;
};
void ASDFrameHolder::setImage(IplImage *sourceImage)
{
image = sourceImage;
};
//-------------------- ASDFrameSequencer -----------------------//
ASDFrameSequencer::~ASDFrameSequencer()
{
close();
};
IplImage *ASDFrameSequencer::getNextImage()
{
return NULL;
};
void ASDFrameSequencer::close()
{
};
bool ASDFrameSequencer::isOpen()
{
return false;
};
void ASDFrameSequencer::getFrameCaption(char* /*caption*/) {
return;
};
IplImage* ASDCVFrameSequencer::getNextImage()
{
IplImage *image;
image = cvQueryFrame(capture);
if (image != NULL)
{
return cvCloneImage(image);
}
else
{
return NULL;
}
};
void ASDCVFrameSequencer::close()
{
if (capture != NULL)
{
cvReleaseCapture(&capture);
}
};
bool ASDCVFrameSequencer::isOpen()
{
return (capture != NULL);
};
//-------------------- ASDFrameSequencerWebCam -----------------------//
bool ASDFrameSequencerWebCam::open(int cameraIndex)
{
close();
capture = cvCaptureFromCAM(cameraIndex);
if (!capture)
{
return false;
}
else
{
return true;
}
};
//-------------------- ASDFrameSequencerVideoFile -----------------------//
bool ASDFrameSequencerVideoFile::open(const char *fileName)
{
close();
capture = cvCaptureFromFile(fileName);
if (!capture)
{
return false;
}
else
{
return true;
}
};
//-------------------- ASDFrameSequencerImageFile -----------------------//
void ASDFrameSequencerImageFile::open(const char *fileNameMask, int startIndex, int endIndex)
{
nCurrentIndex = startIndex-1;
nStartIndex = startIndex;
nEndIndex = endIndex;
std::sprintf(sFileNameMask, "%s", fileNameMask);
};
void ASDFrameSequencerImageFile::getFrameCaption(char *caption) {
std::sprintf(caption, sFileNameMask, nCurrentIndex);
};
IplImage* ASDFrameSequencerImageFile::getNextImage()
{
char fileName[2048];
nCurrentIndex++;
if (nCurrentIndex > nEndIndex)
return NULL;
std::sprintf(fileName, sFileNameMask, nCurrentIndex);
IplImage* img = cvLoadImage(fileName);
return img;
};
void ASDFrameSequencerImageFile::close()
{
nCurrentIndex = nEndIndex+1;
};
bool ASDFrameSequencerImageFile::isOpen()
{
return (nCurrentIndex <= nEndIndex);
};
static void putTextWithShadow(IplImage *img, const char *str, CvPoint point, CvFont *font, CvScalar color = CV_RGB(255, 255, 128))
{
cvPutText(img, str, cvPoint(point.x-1,point.y-1), font, CV_RGB(0, 0, 0));
cvPutText(img, str, point, font, color);
};
#define ASD_RGB_SET_PIXEL(pointer, r, g, b) { (*pointer) = (unsigned char)b; (*(pointer+1)) = (unsigned char)g; (*(pointer+2)) = (unsigned char)r; }
#define ASD_RGB_GET_PIXEL(pointer, r, g, b) {b = (unsigned char)(*(pointer)); g = (unsigned char)(*(pointer+1)); r = (unsigned char)(*(pointer+2));}
static void displayBuffer(IplImage *rgbDestImage, IplImage *buffer, int rValue, int gValue, int bValue)
{
int x, y, nWidth, nHeight;
double destX, destY, dx, dy;
uchar c;
unsigned char *pSrc;
nWidth = buffer->width;
nHeight = buffer->height;
dx = double(rgbDestImage->width)/double(nWidth);
dy = double(rgbDestImage->height)/double(nHeight);
destX = 0;
for (x = 0; x < nWidth; x++)
{
destY = 0;
for (y = 0; y < nHeight; y++)
{
c = ((uchar*)(buffer->imageData + buffer->widthStep*y))[x];
if (c)
{
pSrc = (unsigned char *)rgbDestImage->imageData + rgbDestImage->widthStep*int(destY) + (int(destX)*rgbDestImage->nChannels);
ASD_RGB_SET_PIXEL(pSrc, rValue, gValue, bValue);
}
destY += dy;
}
destY = 0;
destX += dx;
}
};
int main(int argc, char** argv )
{
IplImage *img, *filterMask = NULL;
CvAdaptiveSkinDetector filter(1, CvAdaptiveSkinDetector::MORPHING_METHOD_ERODE_DILATE);
ASDFrameSequencer *sequencer;
CvFont base_font;
char caption[2048], s[256], windowName[256];
long int clockTotal = 0, numFrames = 0;
std::clock_t clock;
if (argc < 4)
{
help(argv);
sequencer = new ASDFrameSequencerWebCam();
(dynamic_cast<ASDFrameSequencerWebCam*>(sequencer))->open(-1);
if (! sequencer->isOpen())
{
std::cout << std::endl << "Error: Cannot initialize the default Webcam" << std::endl << std::endl;
}
}
else
{
sequencer = new ASDFrameSequencerImageFile();
(dynamic_cast<ASDFrameSequencerImageFile*>(sequencer))->open(argv[1], std::atoi(argv[2]), std::atoi(argv[3]) ); // A sequence of images captured from video source, is stored here
}
std::sprintf(windowName, "%s", "Adaptive Skin Detection Algorithm for Video Sequences");
cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
cvInitFont( &base_font, CV_FONT_VECTOR0, 0.5, 0.5);
// Usage:
// c:\>CvASDSample "C:\VideoSequences\sample1\right_view\temp_%05d.jpg" 0 1000
std::cout << "Press ESC to stop." << std::endl << std::endl;
while ((img = sequencer->getNextImage()) != 0)
{
numFrames++;
if (filterMask == NULL)
{
filterMask = cvCreateImage( cvSize(img->width, img->height), IPL_DEPTH_8U, 1);
}
clock = std::clock();
filter.process(img, filterMask); // DETECT SKIN
clockTotal += (std::clock() - clock);
displayBuffer(img, filterMask, 0, 255, 0);
sequencer->getFrameCaption(caption);
std::sprintf(s, "%s - %d x %d", caption, img->width, img->height);
putTextWithShadow(img, s, cvPoint(10, img->height-35), &base_font);
std::sprintf(s, "Average processing time per frame: %5.2fms", (double(clockTotal*1000/CLOCKS_PER_SEC))/numFrames);
putTextWithShadow(img, s, cvPoint(10, img->height-15), &base_font);
cvShowImage (windowName, img);
cvReleaseImage(&img);
if (cvWaitKey(1) == 27)
break;
}
sequencer->close();
delete sequencer;
cvReleaseImage(&filterMask);
cvDestroyWindow(windowName);
std::cout << "Finished, " << numFrames << " frames processed." << std::endl;
return 0;
}
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install, copy or use the software.
//
// Copyright (C) 2009, Farhad Dadgostar
// Intel Corporation and third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's 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.
//
// * The name of Intel Corporation may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "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 Intel Corporation or contributors 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.
//
//M*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
static void help(char **argv)
{
std::cout << "\nThis program demonstrates the contributed flesh detector CvAdaptiveSkinDetector which can be found in contrib.cpp\n"
<< "Usage: " << std::endl <<
argv[0] << " fileMask firstFrame lastFrame" << std::endl << std::endl <<
"Example: " << std::endl <<
argv[0] << " C:\\VideoSequences\\sample1\\right_view\\temp_%05d.jpg 0 1000" << std::endl <<
" iterates through temp_00000.jpg to temp_01000.jpg" << std::endl << std::endl <<
"If no parameter specified, this application will try to capture from the default Webcam." << std::endl <<
"Please note: Background should not contain large surfaces with skin tone." <<
"\n\n ESC will stop\n"
"Using OpenCV version %s\n" << CV_VERSION << "\n"
<< std::endl;
}
class ASDFrameHolder
{
private:
IplImage *image;
double timeStamp;
public:
ASDFrameHolder();
virtual ~ASDFrameHolder();
virtual void assignFrame(IplImage *sourceImage, double frameTime);
inline IplImage *getImage();
inline double getTimeStamp();
virtual void setImage(IplImage *sourceImage);
};
class ASDFrameSequencer
{
public:
virtual ~ASDFrameSequencer();
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
virtual void getFrameCaption(char *caption);
};
class ASDCVFrameSequencer : public ASDFrameSequencer
{
protected:
CvCapture *capture;
public:
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
};
class ASDFrameSequencerWebCam : public ASDCVFrameSequencer
{
public:
virtual bool open(int cameraIndex);
};
class ASDFrameSequencerVideoFile : public ASDCVFrameSequencer
{
public:
virtual bool open(const char *fileName);
};
class ASDFrameSequencerImageFile : public ASDFrameSequencer {
private:
char sFileNameMask[2048];
int nCurrentIndex, nStartIndex, nEndIndex;
public:
virtual void open(const char *fileNameMask, int startIndex, int endIndex);
virtual void getFrameCaption(char *caption);
virtual IplImage *getNextImage();
virtual void close();
virtual bool isOpen();
};
//-------------------- ASDFrameHolder -----------------------//
ASDFrameHolder::ASDFrameHolder( )
{
image = NULL;
timeStamp = 0;
};
ASDFrameHolder::~ASDFrameHolder( )
{
cvReleaseImage(&image);
};
void ASDFrameHolder::assignFrame(IplImage *sourceImage, double frameTime)
{
if (image != NULL)
{
cvReleaseImage(&image);
image = NULL;
}
image = cvCloneImage(sourceImage);
timeStamp = frameTime;
};
IplImage *ASDFrameHolder::getImage()
{
return image;
};
double ASDFrameHolder::getTimeStamp()
{
return timeStamp;
};
void ASDFrameHolder::setImage(IplImage *sourceImage)
{
image = sourceImage;
};
//-------------------- ASDFrameSequencer -----------------------//
ASDFrameSequencer::~ASDFrameSequencer()
{
close();
};
IplImage *ASDFrameSequencer::getNextImage()
{
return NULL;
};
void ASDFrameSequencer::close()
{
};
bool ASDFrameSequencer::isOpen()
{
return false;
};
void ASDFrameSequencer::getFrameCaption(char* /*caption*/) {
return;
};
IplImage* ASDCVFrameSequencer::getNextImage()
{
IplImage *image;
image = cvQueryFrame(capture);
if (image != NULL)
{
return cvCloneImage(image);
}
else
{
return NULL;
}
};
void ASDCVFrameSequencer::close()
{
if (capture != NULL)
{
cvReleaseCapture(&capture);
}
};
bool ASDCVFrameSequencer::isOpen()
{
return (capture != NULL);
};
//-------------------- ASDFrameSequencerWebCam -----------------------//
bool ASDFrameSequencerWebCam::open(int cameraIndex)
{
close();
capture = cvCaptureFromCAM(cameraIndex);
if (!capture)
{
return false;
}
else
{
return true;
}
};
//-------------------- ASDFrameSequencerVideoFile -----------------------//
bool ASDFrameSequencerVideoFile::open(const char *fileName)
{
close();
capture = cvCaptureFromFile(fileName);
if (!capture)
{
return false;
}
else
{
return true;
}
};
//-------------------- ASDFrameSequencerImageFile -----------------------//
void ASDFrameSequencerImageFile::open(const char *fileNameMask, int startIndex, int endIndex)
{
nCurrentIndex = startIndex-1;
nStartIndex = startIndex;
nEndIndex = endIndex;
std::sprintf(sFileNameMask, "%s", fileNameMask);
};
void ASDFrameSequencerImageFile::getFrameCaption(char *caption) {
std::sprintf(caption, sFileNameMask, nCurrentIndex);
};
IplImage* ASDFrameSequencerImageFile::getNextImage()
{
char fileName[2048];
nCurrentIndex++;
if (nCurrentIndex > nEndIndex)
return NULL;
std::sprintf(fileName, sFileNameMask, nCurrentIndex);
IplImage* img = cvLoadImage(fileName);
return img;
};
void ASDFrameSequencerImageFile::close()
{
nCurrentIndex = nEndIndex+1;
};
bool ASDFrameSequencerImageFile::isOpen()
{
return (nCurrentIndex <= nEndIndex);
};
static void putTextWithShadow(IplImage *img, const char *str, CvPoint point, CvFont *font, CvScalar color = CV_RGB(255, 255, 128))
{
cvPutText(img, str, cvPoint(point.x-1,point.y-1), font, CV_RGB(0, 0, 0));
cvPutText(img, str, point, font, color);
};
#define ASD_RGB_SET_PIXEL(pointer, r, g, b) { (*pointer) = (unsigned char)b; (*(pointer+1)) = (unsigned char)g; (*(pointer+2)) = (unsigned char)r; }
#define ASD_RGB_GET_PIXEL(pointer, r, g, b) {b = (unsigned char)(*(pointer)); g = (unsigned char)(*(pointer+1)); r = (unsigned char)(*(pointer+2));}
static void displayBuffer(IplImage *rgbDestImage, IplImage *buffer, int rValue, int gValue, int bValue)
{
int x, y, nWidth, nHeight;
double destX, destY, dx, dy;
uchar c;
unsigned char *pSrc;
nWidth = buffer->width;
nHeight = buffer->height;
dx = double(rgbDestImage->width)/double(nWidth);
dy = double(rgbDestImage->height)/double(nHeight);
destX = 0;
for (x = 0; x < nWidth; x++)
{
destY = 0;
for (y = 0; y < nHeight; y++)
{
c = ((uchar*)(buffer->imageData + buffer->widthStep*y))[x];
if (c)
{
pSrc = (unsigned char *)rgbDestImage->imageData + rgbDestImage->widthStep*int(destY) + (int(destX)*rgbDestImage->nChannels);
ASD_RGB_SET_PIXEL(pSrc, rValue, gValue, bValue);
}
destY += dy;
}
destY = 0;
destX += dx;
}
};
int main(int argc, char** argv )
{
IplImage *img, *filterMask = NULL;
CvAdaptiveSkinDetector filter(1, CvAdaptiveSkinDetector::MORPHING_METHOD_ERODE_DILATE);
ASDFrameSequencer *sequencer;
CvFont base_font;
char caption[2048], s[256], windowName[256];
long int clockTotal = 0, numFrames = 0;
std::clock_t clock;
if (argc < 4)
{
help(argv);
sequencer = new ASDFrameSequencerWebCam();
(dynamic_cast<ASDFrameSequencerWebCam*>(sequencer))->open(-1);
if (! sequencer->isOpen())
{
std::cout << std::endl << "Error: Cannot initialize the default Webcam" << std::endl << std::endl;
}
}
else
{
sequencer = new ASDFrameSequencerImageFile();
(dynamic_cast<ASDFrameSequencerImageFile*>(sequencer))->open(argv[1], std::atoi(argv[2]), std::atoi(argv[3]) ); // A sequence of images captured from video source, is stored here
}
std::sprintf(windowName, "%s", "Adaptive Skin Detection Algorithm for Video Sequences");
cvNamedWindow(windowName, CV_WINDOW_AUTOSIZE);
cvInitFont( &base_font, CV_FONT_VECTOR0, 0.5, 0.5);
// Usage:
// c:\>CvASDSample "C:\VideoSequences\sample1\right_view\temp_%05d.jpg" 0 1000
std::cout << "Press ESC to stop." << std::endl << std::endl;
while ((img = sequencer->getNextImage()) != 0)
{
numFrames++;
if (filterMask == NULL)
{
filterMask = cvCreateImage( cvSize(img->width, img->height), IPL_DEPTH_8U, 1);
}
clock = std::clock();
filter.process(img, filterMask); // DETECT SKIN
clockTotal += (std::clock() - clock);
displayBuffer(img, filterMask, 0, 255, 0);
sequencer->getFrameCaption(caption);
std::sprintf(s, "%s - %d x %d", caption, img->width, img->height);
putTextWithShadow(img, s, cvPoint(10, img->height-35), &base_font);
std::sprintf(s, "Average processing time per frame: %5.2fms", (double(clockTotal*1000/CLOCKS_PER_SEC))/numFrames);
putTextWithShadow(img, s, cvPoint(10, img->height-15), &base_font);
cvShowImage (windowName, img);
cvReleaseImage(&img);
if (cvWaitKey(1) == 27)
break;
}
sequencer->close();
delete sequencer;
cvReleaseImage(&filterMask);
cvDestroyWindow(windowName);
std::cout << "Finished, " << numFrames << " frames processed." << std::endl;
return 0;
}

0
samples/c/build_all.sh Normal file → Executable file
View File

View File

@@ -27,7 +27,7 @@ int main( int argc, char** argv )
if( argc != 4 || strncmp( argv[1], size_opt, strlen(size_opt) ) != 0 )
{
help();
help();
return -1;
}

View File

@@ -5,13 +5,13 @@
#include <stdio.h>
static void help( void )
{
printf("\nThis program demostrates iterative construction of\n"
"delaunay triangulation and voronoi tesselation.\n"
"It draws a random set of points in an image and then delaunay triangulates them.\n"
printf("\nThis program demostrates iterative construction of\n"
"delaunay triangulation and voronoi tesselation.\n"
"It draws a random set of points in an image and then delaunay triangulates them.\n"
"Usage: \n"
"./delaunay \n"
"\nThis program builds the traingulation interactively, you may stop this process by\n"
"hitting any key.\n");
"\nThis program builds the traingulation interactively, you may stop this process by\n"
"hitting any key.\n");
}
static CvSubdiv2D* init_delaunay( CvMemStorage* storage,

10
samples/c/example_cmake/CMakeLists.txt Executable file → Normal file
View File

@@ -1,9 +1,9 @@
PROJECT(opencv_example)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
FIND_PACKAGE( OpenCV REQUIRED )
@@ -14,5 +14,5 @@ TARGET_LINK_LIBRARIES(opencv_example ${OpenCV_LIBS})
#MESSAGE(STATUS "OpenCV_LIBS: ${OpenCV_LIBS}")

20
samples/c/example_cmake/minarea.c Executable file → Normal file
View File

@@ -13,22 +13,22 @@
void help()
{
printf("\nThis program demonstrates finding the minimum enclosing box or circle of a set\n"
"of points using functions: minAreaRect() minEnclosingCircle().\n"
"Random points are generated and then enclosed.\n"
"Call:\n"
"./minarea\n");
printf("\nThis program demonstrates finding the minimum enclosing box or circle of a set\n"
"of points using functions: minAreaRect() minEnclosingCircle().\n"
"Random points are generated and then enclosed.\n"
"Call:\n"
"./minarea\n");
}
int main( int argc, char** argv )
{
IplImage* img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
#if !ARRAY
#if !ARRAY
CvMemStorage* storage = cvCreateMemStorage(0);
#endif
help();
cvNamedWindow( "rect & circle", 1 );
for(;;)
{
char key;
@@ -39,7 +39,7 @@ int main( int argc, char** argv )
CvPoint2D32f center;
CvPoint icenter;
float radius;
#if !ARRAY
#if !ARRAY
CvSeq* ptseq = cvCreateSeq( CV_SEQ_KIND_GENERIC|CV_32SC2, sizeof(CvContour),
sizeof(CvPoint), storage );
for( i = 0; i < count; i++ )
@@ -71,7 +71,7 @@ int main( int argc, char** argv )
cvZero( img );
for( i = 0; i < count; i++ )
{
#if !ARRAY
#if !ARRAY
pt0 = *CV_GET_SEQ_ELEM( CvPoint, ptseq, i );
#else
pt0 = points[i];
@@ -106,7 +106,7 @@ int main( int argc, char** argv )
free( points );
#endif
}
cvDestroyWindow( "rect & circle" );
return 0;
}

0
samples/c/facedetect.cmd Executable file → Normal file
View File

View File

@@ -175,7 +175,7 @@ _cleanup_:
}
else
{
cerr << "Aw snap, couldn't read image " << buf << endl;
cerr << "Aw snap, couldn't read image " << buf << endl;
}
}
fclose(f);
@@ -241,7 +241,7 @@ void detectAndDraw( Mat& img, CascadeClassifier& cascade,
Point center;
Scalar color = colors[i%8];
int radius;
double aspect_ratio = (double)r->width/r->height;
if( 0.75 < aspect_ratio && aspect_ratio < 1.3 )
{

View File

@@ -1,104 +1,104 @@
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#ifdef HAVE_CVCONFIG_H
#include <cvconfig.h>
#endif
#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif
using namespace cv;
static void help()
{
printf( "This program demonstrated the use of the latentSVM detector.\n"
"It reads in a trained object model and then uses that to detect the object in an image\n"
"Call:\n"
"./latentsvmdetect [<image_filename> <model_filename> [<threads_number>]]\n"
" The defaults for image_filename and model_filename are cat.jpg and cat.xml respectively\n"
" Press any key to quit.\n");
}
const char* model_filename = "cat.xml";
const char* image_filename = "cat.jpg";
int tbbNumThreads = -1;
static void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector, int numThreads = -1)
{
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* detections = 0;
int i = 0;
int64 start = 0, finish = 0;
#ifdef HAVE_TBB
tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
if (numThreads > 0)
{
init.initialize(numThreads);
printf("Number of threads %i\n", numThreads);
}
else
{
printf("Number of threads is not correct for TBB version");
return;
}
#endif
start = cvGetTickCount();
detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads);
finish = cvGetTickCount();
printf("detection time = %.3f\n", (float)(finish - start) / (float)(cvGetTickFrequency() * 1000000.0));
#ifdef HAVE_TBB
init.terminate();
#endif
for( i = 0; i < detections->total; i++ )
{
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
CvRect bounding_box = detection.rect;
cvRectangle( image, cvPoint(bounding_box.x, bounding_box.y),
cvPoint(bounding_box.x + bounding_box.width,
bounding_box.y + bounding_box.height),
CV_RGB(255,0,0), 3 );
}
cvReleaseMemStorage( &storage );
}
int main(int argc, char* argv[])
{
help();
if (argc > 2)
{
image_filename = argv[1];
model_filename = argv[2];
if (argc > 3)
{
tbbNumThreads = atoi(argv[3]);
}
}
IplImage* image = cvLoadImage(image_filename);
if (!image)
{
printf( "Unable to load the image\n"
"Pass it as the first parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
return -1;
}
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename);
if (!detector)
{
printf( "Unable to load the model\n"
"Pass it as the second parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
cvReleaseImage( &image );
return -1;
}
detect_and_draw_objects( image, detector, tbbNumThreads );
cvNamedWindow( "test", 0 );
cvShowImage( "test", image );
cvWaitKey(0);
cvReleaseLatentSvmDetector( &detector );
cvReleaseImage( &image );
cvDestroyAllWindows();
return 0;
}
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#ifdef HAVE_CVCONFIG_H
#include <cvconfig.h>
#endif
#ifdef HAVE_TBB
#include "tbb/task_scheduler_init.h"
#endif
using namespace cv;
static void help()
{
printf( "This program demonstrated the use of the latentSVM detector.\n"
"It reads in a trained object model and then uses that to detect the object in an image\n"
"Call:\n"
"./latentsvmdetect [<image_filename> <model_filename> [<threads_number>]]\n"
" The defaults for image_filename and model_filename are cat.jpg and cat.xml respectively\n"
" Press any key to quit.\n");
}
const char* model_filename = "cat.xml";
const char* image_filename = "cat.jpg";
int tbbNumThreads = -1;
static void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector, int numThreads = -1)
{
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* detections = 0;
int i = 0;
int64 start = 0, finish = 0;
#ifdef HAVE_TBB
tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
if (numThreads > 0)
{
init.initialize(numThreads);
printf("Number of threads %i\n", numThreads);
}
else
{
printf("Number of threads is not correct for TBB version");
return;
}
#endif
start = cvGetTickCount();
detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads);
finish = cvGetTickCount();
printf("detection time = %.3f\n", (float)(finish - start) / (float)(cvGetTickFrequency() * 1000000.0));
#ifdef HAVE_TBB
init.terminate();
#endif
for( i = 0; i < detections->total; i++ )
{
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
CvRect bounding_box = detection.rect;
cvRectangle( image, cvPoint(bounding_box.x, bounding_box.y),
cvPoint(bounding_box.x + bounding_box.width,
bounding_box.y + bounding_box.height),
CV_RGB(255,0,0), 3 );
}
cvReleaseMemStorage( &storage );
}
int main(int argc, char* argv[])
{
help();
if (argc > 2)
{
image_filename = argv[1];
model_filename = argv[2];
if (argc > 3)
{
tbbNumThreads = atoi(argv[3]);
}
}
IplImage* image = cvLoadImage(image_filename);
if (!image)
{
printf( "Unable to load the image\n"
"Pass it as the first parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
return -1;
}
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename);
if (!detector)
{
printf( "Unable to load the model\n"
"Pass it as the second parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
cvReleaseImage( &image );
return -1;
}
detect_and_draw_objects( image, detector, tbbNumThreads );
cvNamedWindow( "test", 0 );
cvShowImage( "test", image );
cvWaitKey(0);
cvReleaseLatentSvmDetector( &detector );
cvReleaseImage( &image );
cvDestroyAllWindows();
return 0;
}

View File

@@ -59,12 +59,12 @@ static void ErodeDilate(int pos)
static void help(void)
{
printf( "This program demonstrated the use of the morphology operator, especially open, close, erode, dilate operations\n"
"Morphology operators are built on max (close) and min (open) operators as measured by pixels covered by small structuring elements.\n"
"These operators are very efficient.\n"
"This program also allows you to play with elliptical, rectangluar and cross structure elements\n"
"Morphology operators are built on max (close) and min (open) operators as measured by pixels covered by small structuring elements.\n"
"These operators are very efficient.\n"
"This program also allows you to play with elliptical, rectangluar and cross structure elements\n"
"Usage: \n"
"./morphologyc [image_name -- Default baboon.jpg]\n"
"\nHot keys: \n"
"./morphologyc [image_name -- Default baboon.jpg]\n"
"\nHot keys: \n"
"\tESC - quit the program\n"
"\tr - use rectangle structuring element\n"
"\te - use elliptic structuring element\n"

View File

@@ -7,14 +7,14 @@
static void help(void)
{
printf(
"\nThis program demonstrated the use of motion templates -- basically using the gradients\n"
"of thresholded layers of decaying frame differencing. New movements are stamped on top with floating system\n"
"time code and motions too old are thresholded away. This is the 'motion history file'. The program reads from the camera of your choice or from\n"
"a file. Gradients of motion history are used to detect direction of motoin etc\n"
printf(
"\nThis program demonstrated the use of motion templates -- basically using the gradients\n"
"of thresholded layers of decaying frame differencing. New movements are stamped on top with floating system\n"
"time code and motions too old are thresholded away. This is the 'motion history file'. The program reads from the camera of your choice or from\n"
"a file. Gradients of motion history are used to detect direction of motoin etc\n"
"Usage :\n"
"./motempl [camera number 0-n or file name, default is camera 0]\n"
);
"./motempl [camera number 0-n or file name, default is camera 0]\n"
);
}
// various tracking parameters (in seconds)
const double MHI_DURATION = 1;

View File

@@ -20,8 +20,8 @@
static void help()
{
printf("\nThis program demonstrates the one way interest point descriptor found in features2d.hpp\n"
"Correspondences are drawn\n");
printf("\nThis program demonstrates the one way interest point descriptor found in features2d.hpp\n"
"Correspondences are drawn\n");
printf("Format: \n./one_way_sample <path_to_samples> <image1> <image2>\n");
printf("For example: ./one_way_sample . ../c/scene_l.bmp ../c/scene_r.bmp\n");
}
@@ -39,7 +39,7 @@ int main(int argc, char** argv)
if (argc != 4)
{
help();
help();
return 0;
}
@@ -50,14 +50,14 @@ int main(int argc, char** argv)
printf("Reading the images...\n");
Mat img1 = imread(img1_name, CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(img2_name, CV_LOAD_IMAGE_GRAYSCALE);
// extract keypoints from the first image
SURF surf_extractor(5.0e3);
vector<KeyPoint> keypoints1;
// printf("Extracting keypoints\n");
surf_extractor(img1, Mat(), keypoints1);
printf("Extracted %d keypoints...\n", (int)keypoints1.size());
printf("Training one way descriptors... \n");
@@ -101,18 +101,18 @@ Mat DrawCorrespondences(const Mat& img1, const vector<KeyPoint>& features1, cons
cvtColor(img1, part, COLOR_GRAY2RGB);
part = img_corr(Rect(img1.cols, 0, img2.cols, img2.rows));
cvtColor(img1, part, COLOR_GRAY2RGB);
for (size_t i = 0; i < features1.size(); i++)
{
circle(img_corr, features1[i].pt, 3, CV_RGB(255, 0, 0));
}
for (size_t i = 0; i < features2.size(); i++)
{
Point pt((int)features2[i].pt.x + img1.cols, (int)features2[i].pt.y);
circle(img_corr, pt, 3, Scalar(0, 0, 255));
line(img_corr, features1[desc_idx[i]].pt, pt, Scalar(0, 255, 0));
}
return img_corr;
}

View File

@@ -8,10 +8,10 @@
static void help( void )
{
printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
printf("\nThis program illustrates Linear-Polar and Log-Polar image transforms\n"
"Usage :\n"
"./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n"
);
"./polar_transforms [[camera number -- Default 0],[AVI path_filename]]\n\n"
);
}
int main( int argc, char** argv )
{
@@ -61,7 +61,7 @@ int main( int argc, char** argv )
cvLinearPolar(frame,lin_polar_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
#if 0
cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR);
cvLogPolar(log_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR);
#else
cvLinearPolar(lin_polar_img,recovered_img,cvPoint2D32f(frame->width >> 1,frame->height >> 1),70, CV_WARP_INVERSE_MAP+CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS);
#endif

View File

@@ -6,11 +6,11 @@
static void help(void)
{
printf("\nThis program demonstrated color pyramid segmentation cvcvPyrSegmentation() which is controlled\n"
"by two trhesholds which can be manipulated by a trackbar. It can take an image file name or defaults to 'fruits.jpg'\n"
printf("\nThis program demonstrated color pyramid segmentation cvcvPyrSegmentation() which is controlled\n"
"by two trhesholds which can be manipulated by a trackbar. It can take an image file name or defaults to 'fruits.jpg'\n"
"Usage :\n"
"./pyaramid_segmentation [image_path_filename -- Defaults to fruits.jpg]\n\n"
);
"./pyaramid_segmentation [image_path_filename -- Defaults to fruits.jpg]\n\n"
);
}
IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;