📄 shadingcorrectionsample.cpp
字号:
//-----------------------------------------------------------------------------
// (c) 2002 by Basler Vision Technologies
// Section: Vision Components
// Project: BCAM
// $Header: ShadingCorrectionSample.cpp, 3, 01.10.2002 17:00:50, Nebelung, H.$
//-----------------------------------------------------------------------------
/**
* \file ShadingCorrectionSample.cpp
* \brief Usage of shading correction.
*
* This sample program demonstrates the BCAM Api's support of the shading correction feature.
* The program creates a shading correction table, uploads it into the camera and activates
* the appropriate shading correction mode.
*
*/
#include "stdafx.h"
#include "ShadingCorrectionSample.h"
#include <bcam.h>
#include <createcorrectiontable.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
/*!
* The shading correction demonstration.
*
*/
int shadingCorrection()
{
const int imageSize = 640 * 480;
// Allocate buffer for the shading table
PBYTE pTable = new BYTE[imageSize];
try
{
// Check if a camera is present
if ( CBcam::DeviceNames().empty() )
{
cerr << "No camera device found!" << endl;
delete[] pTable;
return 1;
}
// Get the devicename of the first camera
CString DeviceName = *(CBcam::DeviceNames().begin());
// Create the driver object and open the driver
CBcam Bcam;
Bcam.Open(DeviceName);
// Check if the device supports the shading correction feature
if ( ! Bcam.ShadingCorrection.IsSupported() )
{
cerr << "The camera doesn't support the shading correction feature" << endl;
delete[] pTable;
return 1;
}
// Setting VideoFormat=0, VideoMode=5 yields 640 x 480, Mono8
if ( ! Bcam.IsVideoModeSupported(DCS_Format0, DCS_Mode5) )
{
cerr << "Camera doesn't support format 0, mode 5." << endl;
delete[] pTable;
return 1;
}
// select the fastest supported mode
if ( Bcam.IsVideoModeSupported(DCS_Format0, DCS_Mode5, DCS_30fps) )
Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_30fps);
else if ( Bcam.IsVideoModeSupported(DCS_Format0, DCS_Mode5, DCS_15fps) )
Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_15fps);
else if ( Bcam.IsVideoModeSupported(DCS_Format0, DCS_Mode5, DCS_7_5fps) )
Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_3_75fps);
else if ( Bcam.IsVideoModeSupported(DCS_Format0, DCS_Mode5, DCS_3_75fps) )
Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_3_75fps);
else Bcam.SetVideoMode(DCS_Format0, DCS_Mode5, DCS_1_875fps);
// Allocate resources
Bcam.AllocateResources(1, imageSize);
// Create the shading correction table.
// The function will grab 100 images to create an average image. The average image
// is used to calculate the correction table. The function returns the proper shading
// correction mode (1:3 or 1:5).
cout << "Calculating shading correction table" << endl;
if ( Bcam.ShadingCorrection() != SCM_Disabled )
Bcam.ShadingCorrection = SCM_Disabled; // shading correction must be disabled before calculating the correction data :-)
SCMode_t shadingMode = CreateShadingCorrectionTable(1000, Bcam, pTable);
if ( shadingMode == SCM_Disabled )
{
cerr << "Could not calculate a correction table." << endl;
delete[] pTable;
return 1;
}
// Upload the shading correction table into the camera.
// The upload function allows to specify a call back function, which is called each
// n bytes. This call back function can be used to display the progress of the upload
// operation.
cout << "Uploading shading correction table";
const int n = 4096; // Every 4096 bytes we are informed about the upload progress
Bcam.ShadingCorrection.SetImage(pTable, // Pointer to correcttion table
imageSize, // Size of table
1000, // Timeout of 1000ms to upload n bytes
&ProgressCallbackProc, // The callback function
n, // The callback function is called every n bytes
NULL // We could pass additional context information to the callback
// function, for example an instance pointer
);
cout << "done." << endl;
// Enable the shading correction
Bcam.ShadingCorrection = shadingMode;
}
catch ( BcamException e )
{
cerr << " Error: " << (LPCTSTR) e.Description() << endl;
return 1;
}
delete[] pTable;
return 0;
}
/*!
* Callback function which is periodically called by the upload mechanism.
* We must return true to continue the upload procedure or false to cancel it.
* The parameter written informs us about the number of bytes already written.
* The pointer pContext can be used to pass additional information to the callback
* function, e.g. pContext could be an instance pointer.
*/
bool ProgressCallbackProc(int written, void* pContext)
{
cout << "." ;
return true; // continue the upload procedure
}
/*!
* The application's main function
*
*/
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
cout << "Shading Correction Sample" << endl;
cout << "=========================" << endl << endl;
// run the demonstration
nRetCode = shadingCorrection();
}
cout << endl << endl << "Press enter key." << endl;
cin.get();
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -