|
@@ -1,6 +1,7 @@
|
|
|
#include "stdafx.h"
|
|
|
#include "DocScannerCap.h"
|
|
|
#include "math.h"
|
|
|
+#include "UserEventCode.h"
|
|
|
//template<typename T>
|
|
|
//struct identity
|
|
|
//{
|
|
@@ -144,12 +145,9 @@ int IsDeviceBusy(const char* lpcszDeviceName)
|
|
|
}
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
|
|
|
- int count = 0;
|
|
|
- char tmp[255] = {0};
|
|
|
- while (varName.bstrVal[count] != 0x00 && count < 255) {
|
|
|
- tmp[count] = (char)varName.bstrVal[count];
|
|
|
- count++;
|
|
|
- }
|
|
|
+ int count = 255;
|
|
|
+ char tmp[256] = {0};
|
|
|
+ WrapW2A(varName, tmp, count);
|
|
|
if(SUCCEEDED(hr)) {
|
|
|
if(!strcmp(lpcszDeviceName, tmp)) {
|
|
|
//Deal the specific device
|
|
@@ -219,7 +217,8 @@ int IsDeviceBusy(const char* lpcszDeviceName)
|
|
|
videoBusy = 0;
|
|
|
}
|
|
|
else {
|
|
|
- Dbg("It works ? %d, %d", i, j);
|
|
|
+ LogWarn(Severity_Low, Error_DevCommFailed, LOG_ERROR_PORTABLESCANNER_BUSY_ONE,
|
|
|
+ CSimpleStringA::Format("%s stop failed: %d", lpcszDeviceName, innhr));
|
|
|
}
|
|
|
SAFE_RELEASE_IDEV(m_pVW);
|
|
|
SAFE_RELEASE_IDEV(m_pMC);
|
|
@@ -229,8 +228,7 @@ int IsDeviceBusy(const char* lpcszDeviceName)
|
|
|
}
|
|
|
if (videoBusy == 1)
|
|
|
{
|
|
|
- Dbg("Test 1");
|
|
|
- nRet = 1; //瑙嗛�璁惧�鍗犵敤
|
|
|
+ nRet = 1; //视频设备占用
|
|
|
}
|
|
|
SAFE_RELEASE_IDEV(pXBar1);
|
|
|
}
|
|
@@ -250,8 +248,9 @@ int IsDeviceBusy(const char* lpcszDeviceName)
|
|
|
HRESULT innhr = m_pMC->StopWhenReady();
|
|
|
if (FAILED(innhr))
|
|
|
{
|
|
|
- Dbg("Test 2");
|
|
|
- nRet = 1; //瑙嗛�璁惧�鍗犵敤
|
|
|
+ LogWarn(Severity_Low, Error_DevCommFailed, LOG_ERROR_PORTABLESCANNER_BUSY_TWO,
|
|
|
+ CSimpleStringA::Format("%s stop failed: %d", lpcszDeviceName, innhr));
|
|
|
+ nRet = 1; //视频设备占用
|
|
|
}
|
|
|
SAFE_RELEASE_IDEV(m_pVW);
|
|
|
SAFE_RELEASE_IDEV(m_pMC);
|
|
@@ -272,7 +271,6 @@ int IsDeviceBusy(const char* lpcszDeviceName)
|
|
|
PEnd:
|
|
|
SAFE_RELEASE_IDEV(pDevEnum);
|
|
|
SAFE_RELEASE_IDEV(pEnum);
|
|
|
- Dbg("IsDeviceBusy(%s) returned %d", lpcszDeviceName, nRet);
|
|
|
if(nRet != 1) {
|
|
|
nRet = 0;
|
|
|
}
|
|
@@ -373,7 +371,6 @@ int ExclusiveCameraBuckes(const CAMERA_BUCKET& lhs, const CAMERA_BUCKET& rhs, CA
|
|
|
|
|
|
void DisplayCameraInfos(const CAMERA_BUCKET& vtCameraList)
|
|
|
{
|
|
|
- Dbg("Cameralist:(%d)", vtCameraList.size());
|
|
|
for(CAMERA_BUCKET_CITER it=vtCameraList.cbegin(); it!=vtCameraList.cend(); ++it) {
|
|
|
if(*it) {
|
|
|
(*it)->Display();
|
|
@@ -427,10 +424,7 @@ CDocScannerCap::~CDocScannerCap(void)
|
|
|
_cleanup(false);
|
|
|
|
|
|
RequestQueueCleanup();
|
|
|
- //Would meet confict ?
|
|
|
- Dbg("before destroyAllWindows...");
|
|
|
destroyAllWindows();
|
|
|
- Dbg("after destroyAllWindows...");
|
|
|
|
|
|
#endif
|
|
|
|
|
@@ -549,7 +543,7 @@ bool CDocScannerCap::Open(unsigned int idx)
|
|
|
//the method first call release to close alreay opened file or camera
|
|
|
m_cvCap.open(idx);
|
|
|
if(!m_cvCap.isOpened()) {
|
|
|
- Dbg("open failed:");
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("open failed:");
|
|
|
m_dwErrCode = ERROR_OPEN_FAILED;
|
|
|
winName.clear();
|
|
|
return false;
|
|
@@ -575,7 +569,7 @@ bool CDocScannerCap::Open(unsigned int idx)
|
|
|
|
|
|
void CDocScannerCap::_setProperty()
|
|
|
{
|
|
|
- //璁剧疆涓轰笉涓€鏍风殑鍒嗚鲸鐜囷紝浼氬嚭鐜拌€楁椂锛�1.5s 闀垮煄
|
|
|
+ //设置为不一样的分辨率,会出现耗时,1.5s 长城
|
|
|
//SetResoultionRatio(1920, 1080);
|
|
|
}
|
|
|
|
|
@@ -589,7 +583,7 @@ bool CDocScannerCap::OpenCamera(LPCTSTR lpcszDev)
|
|
|
const int camId = _getCamIDByDevName(lpcszDev);
|
|
|
if(camId < 0) {
|
|
|
m_dwErrCode = ERROR_FILE_NOT_FOUND;
|
|
|
- Dbg("not found camera id.");
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("not found camera id.");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -620,7 +614,7 @@ bool CDocScannerCap::OpenCamera(LPCTSTR lpcszDev)
|
|
|
bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
|
|
|
{
|
|
|
if(!m_fPreviewing) {
|
|
|
- Dbg("Request scaning without in previewing.");
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Request scaning without in previewing.");
|
|
|
m_dwErrCode = ERROR_INVALID_ENVIRONMENT;
|
|
|
return false;
|
|
|
}
|
|
@@ -648,13 +642,12 @@ bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
|
|
|
|
|
|
RequestEventPtr item = CreateRequestEvent(EVTCODE_SCAN);
|
|
|
if(!item) {
|
|
|
- Dbg("CreateRequestEvent failed");
|
|
|
m_dwErrCode = ERROR_RESOURCE_FAILED;
|
|
|
return false;
|
|
|
}
|
|
|
item->evtData = (CHAR*)malloc(sizeof(char)*(len+1));
|
|
|
if(item->evtData == NULL) {
|
|
|
- Dbg("malloc failed");
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("malloc failed");
|
|
|
m_dwErrCode = ERROR_RESOURCE_FAILED;
|
|
|
delete item;
|
|
|
return false;
|
|
@@ -663,22 +656,13 @@ bool CDocScannerCap::ScanImage(const char* lpcszFilePath)
|
|
|
strcpy_s(item->evtData, sizeof(char)*(len+1), szFileName);
|
|
|
item->dwDataLen = len+1;
|
|
|
PostIntoRequestQueue(&item);
|
|
|
- Dbg("WaitForResponse...");
|
|
|
int nRes = WaitForResponse(EVTCODE_SCAN, 30*1000);
|
|
|
- Dbg("WaitForResponse returned: 0x%02x", nRes);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WaitForResponse returned: 0x%02x", nRes);
|
|
|
if(nRes >= EVTSTATUS_ERROR_MASK) {
|
|
|
|
|
|
}
|
|
|
else if(nRes == EVTSTATUS_DONE_SUCC) {
|
|
|
- Dbg("Scan succ: %d[%s]", ExistsFileA(szFileName), szFileName);
|
|
|
- //Mat picture = imread(szFileName);
|
|
|
- //if(!picture.empty()) {
|
|
|
- // namedWindow("show-img");
|
|
|
- // imshow("show-img", picture);
|
|
|
- //}
|
|
|
- //else {
|
|
|
- // Dbg("picture is empty!!");
|
|
|
- //}
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Scan succ: %d[%s]", ExistsFileA(szFileName), szFileName);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
@@ -708,12 +692,10 @@ bool CDocScannerCap::StartPreview()
|
|
|
{
|
|
|
m_hPreviewPro = NULL;
|
|
|
m_dwErrCode = E_HANDLE;
|
|
|
- Dbg("Create WndPreviewDlgProc thread failed");
|
|
|
return false;
|
|
|
}
|
|
|
m_fPreviewing = true;
|
|
|
if(ResumeThread(m_hPreviewPro) == (DWORD)-1) {
|
|
|
- Dbg("ResumeThread failed, GLE=%u", GetLastError());
|
|
|
m_dwErrCode = E_UNEXPECTED;
|
|
|
m_fPreviewing = false;
|
|
|
CloseHandle(m_hPreviewPro);
|
|
@@ -731,17 +713,16 @@ bool CDocScannerCap::TerminatePreview()
|
|
|
m_dwErrCode = E_UNEXPECTED;
|
|
|
m_tpStopPreview = true;
|
|
|
//30 seconds to timeout?
|
|
|
- Dbg("Set StopPreivew flag true, waitting...");
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set StopPreivew flag true, waitting...");
|
|
|
DWORD dwResult = WaitForSingleObject(m_hPreviewPro, 30 * 1000);
|
|
|
if(dwResult == WAIT_OBJECT_0) {
|
|
|
- Dbg("Wait succ.");
|
|
|
- //assert(m_fPreviewing == false);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Wait succ.");
|
|
|
CloseHandle(m_hPreviewPro);
|
|
|
m_hPreviewPro = NULL;
|
|
|
m_dwErrCode = ERROR_SUCCESS;
|
|
|
return true;
|
|
|
}else if(dwResult == WAIT_TIMEOUT) {
|
|
|
- Dbg("Wait succ timeout: %d", m_fPreviewing);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Wait succ timeout: %d", m_fPreviewing);
|
|
|
if(!m_fPreviewing) {
|
|
|
CloseHandle(m_hPreviewPro);
|
|
|
m_hPreviewPro = NULL;
|
|
@@ -751,7 +732,7 @@ bool CDocScannerCap::TerminatePreview()
|
|
|
m_dwErrCode = WAIT_TIMEOUT;
|
|
|
}
|
|
|
else {
|
|
|
- Dbg("WaitForSingleObject failed returned: %u.", dwResult);
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("WaitForSingleObject failed returned: %u.", dwResult);
|
|
|
m_dwErrCode = dwResult;
|
|
|
}
|
|
|
}
|
|
@@ -770,13 +751,12 @@ bool CDocScannerCap::_initWindow(bool fShown)
|
|
|
if(m_defWnd == NULL) {
|
|
|
destroyWindow(winName);
|
|
|
m_dwErrCode = ERROR_INVALID_WINDOW_HANDLE;
|
|
|
- Dbg("Find %s window handle faiiled, GLE=%u", winName.c_str(), GetLastError());
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("Find %s window handle faiiled, GLE=%u", winName.c_str(), GetLastError());
|
|
|
return false;
|
|
|
}
|
|
|
DWORD dwFlag = fShown ? SWP_SHOWWINDOW : SWP_HIDEWINDOW;
|
|
|
BOOL bRet = ::SetWindowPos(m_defWnd, HWND_TOPMOST,
|
|
|
m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height, dwFlag);
|
|
|
- Dbg("WinSize(%d): %d, %d, %d, %d", bRet, m_winSize.x, m_winSize.y, m_winSize.width, m_winSize.height);
|
|
|
if(bRet) { m_bHide = !fShown; }
|
|
|
m_dwErrCode = ERROR_SUCCESS;
|
|
|
rectStatus = NOT_SET;
|
|
@@ -790,12 +770,15 @@ void CDocScannerCap::_destroyWindow()
|
|
|
m_cmFrame.release();
|
|
|
}
|
|
|
if(m_defWnd) {
|
|
|
- Dbg("before destroyWindow with %s", winName.c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before destroyWindow with %s", winName.c_str());
|
|
|
destroyWindow(winName);
|
|
|
- Dbg("after destroyWindow with %s", winName.c_str());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after destroyWindow with %s", winName.c_str());
|
|
|
m_defWnd = NULL;
|
|
|
m_bHide = FALSE;
|
|
|
}
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before destroyAllWindow");
|
|
|
+ destroyAllWindows();
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after destroyAllWindow");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -816,7 +799,6 @@ UINT WINAPI CDocScannerCap::WndPreviewDlgProc(PVOID param)
|
|
|
{
|
|
|
CDocScannerCap *pCap = reinterpret_cast<CDocScannerCap*>(param);
|
|
|
if(pCap == NULL) {
|
|
|
- Dbg("WndPreviewDlgProc::praram is invalid(empty)");
|
|
|
return UINT(-1);
|
|
|
}
|
|
|
return (UINT)(pCap->_executePreview());
|
|
@@ -824,18 +806,17 @@ UINT WINAPI CDocScannerCap::WndPreviewDlgProc(PVOID param)
|
|
|
|
|
|
void CDocScannerCap::EvtFinishedHandle(USHORT evtCode, UCHAR result, UINT checksum)
|
|
|
{
|
|
|
- Dbg("EvtCode:%d, result:%d, checksum:%d", evtCode, result, checksum);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void CDocScannerCap::SetResoultionRatio(int width, int height, int nframes /*= -1*/)
|
|
|
{
|
|
|
- Dbg("before: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH),
|
|
|
- (int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
|
|
|
+ // DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("before: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH),
|
|
|
+ // (int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
|
|
|
m_cvCap.set(CV_CAP_PROP_FRAME_WIDTH, width);
|
|
|
m_cvCap.set(CV_CAP_PROP_FRAME_HEIGHT, height);
|
|
|
- Dbg("after: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH),
|
|
|
- (int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
|
|
|
- //m_cvCap.set(CAP_PROP_CONVERT_RGB, 0);
|
|
|
+ // DDbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)g("after: width=%d, height=%d , nframes=%d", (int)m_cvCap.get(CAP_PROP_FRAME_WIDTH),
|
|
|
+ // (int)m_cvCap.get(CAP_PROP_FRAME_HEIGHT), (int)m_cvCap.get(CAP_PROP_FRAME_COUNT));
|
|
|
}
|
|
|
|
|
|
void CDocScannerCap::_setMouseCallback()
|
|
@@ -847,24 +828,13 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
|
|
|
{
|
|
|
//static Rect origin;
|
|
|
if(event == CV_EVENT_LBUTTONDOWN) {
|
|
|
-
|
|
|
- //if(rectStatus == NOT_SET)
|
|
|
- {
|
|
|
- //Dbg("CV_EVENT_LBUTTONDOWN");
|
|
|
- rectStatus = IN_PROCESS;
|
|
|
- rect = Rect(x, y, 0, 0);
|
|
|
- //origin = rect;
|
|
|
- }
|
|
|
+ rectStatus = IN_PROCESS;
|
|
|
+ rect = Rect(x, y, 0, 0);
|
|
|
|
|
|
} else if(event == CV_EVENT_MOUSEMOVE) {
|
|
|
|
|
|
if(rectStatus == IN_PROCESS) {
|
|
|
rect = Rect(Point(rect.x, rect.y), Point(x,y));
|
|
|
- //rect.x = MIN(origin.x, x);
|
|
|
- //rect.y = MIN(origin.y, y);
|
|
|
- //rect.width = abs(origin.x - x);
|
|
|
- //rect.height = abs(origin.y - y);
|
|
|
- //Dbg("CV_EVENT_MOUSEMOVE: %d,%d,%d,%d TID(%u)", rect.x, rect.y, rect.width, rect.height, GetCurrentThreadId());
|
|
|
}
|
|
|
|
|
|
}else if(event == CV_EVENT_LBUTTONUP) {
|
|
@@ -872,12 +842,10 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
|
|
|
if(rectStatus == IN_PROCESS) {
|
|
|
|
|
|
if(rect.height == 0 || rect.width == 0) {
|
|
|
- Dbg("CV_EVENT_LBUTTONUP::Zero Area");
|
|
|
rectStatus = NOT_SET;
|
|
|
return;
|
|
|
}
|
|
|
rect = Rect(Point(rect.x, rect.y), Point(x,y));
|
|
|
- Dbg("CV_EVENT_LBUTTONUP");
|
|
|
rectStatus = SET;
|
|
|
}
|
|
|
}
|
|
@@ -885,36 +853,13 @@ void CDocScannerCap::MouseClick(int event, int x, int y, int flags)
|
|
|
|
|
|
void CDocScannerCap::_setResizeArea(float ratio)
|
|
|
{
|
|
|
- //m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[0] = 0;
|
|
|
- //m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[1] = 0;
|
|
|
- //m_cmFrame.at<Vec3b>(m_cmFrame.cols / 2, m_cmFrame.rows / 2)[2] = 255;
|
|
|
- //putText(m_cmFrame, "Hello", Point(m_cmFrame.cols/2, m_cmFrame.rows/2), 0, 0.7, Scalar(255, 0, 0));
|
|
|
Rect area((1-ratio)/2*m_cmFrame.cols, (1-ratio)/2*m_cmFrame.rows, ratio*m_cmFrame.cols, ratio*m_cmFrame.rows);
|
|
|
-
|
|
|
- //Mat mask;
|
|
|
- //mask.create(m_cmFrame.size(), CV_8UC1);
|
|
|
- //mask.setTo( GC_BGD );
|
|
|
- //(mask(area)).setTo( Scalar(GC_PR_FGD));
|
|
|
-
|
|
|
- //Mat binMask;
|
|
|
- //if( binMask.empty() || binMask.rows != mask.rows || binMask.cols != mask.cols )
|
|
|
- // binMask.create(mask.size(), CV_8UC1 );
|
|
|
- //binMask = mask & 1;
|
|
|
- //m_cmFrame.copyTo(res, binMask);
|
|
|
- //WRITE_INFO_PARAM("w, h: %d, %d", m_cmFrame.cols, m_cmFrame.rows);
|
|
|
- //WRITE_INFO_PARAM("x, y, w, h: %d, %d, %d, %d", area.x, area.y, area.width, area.height);
|
|
|
Mat roi = m_cmFrame(area);
|
|
|
Mat res;
|
|
|
res.create(roi.rows, roi.cols, m_cmFrame.type());
|
|
|
roi.copyTo(res);
|
|
|
- //WRITE_INFO_PARAM("2 w, h: %d, %d", res.cols, res.rows);
|
|
|
m_cmFrame.release();
|
|
|
m_cmFrame = res;
|
|
|
-
|
|
|
- //rectangle(m_cmFrame, Point(area.x, area.y),
|
|
|
- // Point(area.x + area.width, area.y + area.height),
|
|
|
- // RED, rectangle_thickness);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
void CDocScannerCap::_setInterestArea()
|
|
@@ -922,7 +867,6 @@ void CDocScannerCap::_setInterestArea()
|
|
|
if(rectStatus == IN_PROCESS || rectStatus == SET) {
|
|
|
|
|
|
Rect area(rect);
|
|
|
- //Dbg("rect: %d, %d, %d, %d", rect.x, rect.y, rect.width, rect.height);
|
|
|
int suffix_x = rect.x - drawableRect.x;
|
|
|
int suffix_y = rect.y - drawableRect.y;
|
|
|
|
|
@@ -939,10 +883,8 @@ void CDocScannerCap::_setInterestArea()
|
|
|
Point(area.x + area.width, area.y + area.height),
|
|
|
GREEN, rectangle_thickness);
|
|
|
assert(m_cmFrame.data);
|
|
|
- //Dbg("drawableRect: %d, %d, %d, %d", drawableRect.x, drawableRect.y, drawableRect.width, drawableRect.height);
|
|
|
const CvScalar colorMask = cvScalarAll(-52);
|
|
|
Mat res = Mat::ones(m_cmFrame.size(), CV_8UC1)*255;
|
|
|
- //Dbg("area: %d, %d, %d, %d", area.x, area.y, area.width, area.height);
|
|
|
res(area).setTo(0);
|
|
|
cv::add(m_cmFrame, (const cv::Scalar&)colorMask, m_cmFrame, res, m_cmFrame.type());
|
|
|
rect = area;
|
|
@@ -979,14 +921,14 @@ bool CDocScannerCap::_executePreview()
|
|
|
|
|
|
if(eOccurTimes == 0) {
|
|
|
eOccurTimes++;
|
|
|
- Dbg("Wow! the scanner has problem");
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Wow! the scanner has problem");
|
|
|
dwEStartTick = GetTickCount();
|
|
|
|
|
|
}else if(eOccurTimes != -1) {
|
|
|
eOccurTimes++;
|
|
|
if(eOccurTimes >= ERROR_CONTINUE_TIMES
|
|
|
|| GetTickCount() > dwEStartTick + ERROR_CONTINUE_MILLSEC) {
|
|
|
- Dbg("Send Reset Event !! %d", eOccurTimes);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Send Reset Event !! %d", eOccurTimes);
|
|
|
eOccurTimes = -1;
|
|
|
SetResetEvent();
|
|
|
}
|
|
@@ -999,12 +941,12 @@ bool CDocScannerCap::_executePreview()
|
|
|
if(B == G && G == R && B == 0) {
|
|
|
|
|
|
if(eClosedTimes == 0) {
|
|
|
- Dbg("Eh, maybe forget to scratch the scanner");
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Eh, maybe forget to scratch the scanner");
|
|
|
eClosedTimes = 1;
|
|
|
}
|
|
|
|
|
|
}else if(eClosedTimes != 0){
|
|
|
- Dbg("Ok, you achieve it");
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Ok, you achieve it");
|
|
|
eClosedTimes = 0;
|
|
|
}
|
|
|
|
|
@@ -1015,7 +957,7 @@ bool CDocScannerCap::_executePreview()
|
|
|
}
|
|
|
|
|
|
if(eClosedTimes != 0){
|
|
|
- Dbg("Ok, you achieve it");
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Ok, you achieve it");
|
|
|
eClosedTimes = 0;
|
|
|
}
|
|
|
}
|
|
@@ -1031,7 +973,7 @@ bool CDocScannerCap::_executePreview()
|
|
|
|
|
|
Mat origin = m_cmFrame.clone();
|
|
|
int cols = 0, rows = 0;
|
|
|
- {//濉�厖杈规�浠ラ€傚簲瀹藉害
|
|
|
+ {//填充边框以适应宽度
|
|
|
Size origin_size = m_cmFrame.size();
|
|
|
if(1.0*m_winSize.width / m_winSize.height > 1) {
|
|
|
int aimWidth = (int)(1.0*origin_size.height*(1.0*m_winSize.width / m_winSize.height));
|
|
@@ -1056,8 +998,6 @@ bool CDocScannerCap::_executePreview()
|
|
|
if(cols > 0 || rows > 0) {
|
|
|
copyMakeBorder(m_cmFrame, m_cmFrame, rows, rows, cols, cols, BORDER_CONSTANT, BLACK);
|
|
|
}
|
|
|
- //Dbg("m_winSize: %d, %d", m_winSize.width, m_winSize.height);
|
|
|
- //Dbg("m_cmFrame: %d, %d", m_cmFrame.cols, m_cmFrame.rows);
|
|
|
drawableRect.x = cols;
|
|
|
drawableRect.width = origin.cols;
|
|
|
drawableRect.y = rows;
|
|
@@ -1068,12 +1008,12 @@ bool CDocScannerCap::_executePreview()
|
|
|
imshow(winName, m_cmFrame);
|
|
|
char keyCode = cvWaitKey(WAITKEY_TIME);
|
|
|
//if(keyCode == 27) {
|
|
|
- // Dbg("ESC key press event recv.");
|
|
|
+ // DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ESC key press event recv.");
|
|
|
// break;
|
|
|
//}
|
|
|
RequestEventPtr evtPtr = GetRequest();
|
|
|
if(evtPtr) {
|
|
|
- Dbg("0x%02x event recv.", evtPtr->evtCode);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("0x%02x event recv.", evtPtr->evtCode);
|
|
|
switch(evtPtr->evtCode)
|
|
|
{
|
|
|
case EVTCODE_SCAN:
|
|
@@ -1090,43 +1030,22 @@ bool CDocScannerCap::_executePreview()
|
|
|
|
|
|
if(rectStatus == SET && (rect.width != 0 && rect.height != 0)) {
|
|
|
Mat result(picture, rect);
|
|
|
- //imwrite(szFileName, result);
|
|
|
- Dbg("ScanImage@1: %s %d", szFileName, result.size());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ScanImage@1: %s %d", szFileName, result.size());
|
|
|
testMat = result.clone();
|
|
|
-
|
|
|
} else {
|
|
|
- //imwrite(szFileName, origin);
|
|
|
- Dbg("ScanImage@2: %s %d", szFileName, origin.size());
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("ScanImage@2: %s %d", szFileName, origin.size());
|
|
|
testMat = origin.clone();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
ImageWriteUntil(szFileName, testMat);
|
|
|
|
|
|
- //cv::Mat destMat;
|
|
|
- /*int compatRate = MatResize(testMat, destMat, 100);
|
|
|
- compatRate = compatRate > 0 ? compatRate + 1: 100;*/
|
|
|
- //const int compatRate = 90;
|
|
|
- //Dbg("set compress rate: %d", compatRate);
|
|
|
- //vector<int> comprressionParams;
|
|
|
- //comprressionParams.push_back(CV_IMWRITE_JPEG_QUALITY);
|
|
|
- //comprressionParams.push_back(compatRate);
|
|
|
- //default one
|
|
|
- //comprressionParams.push_back(IMWRITE_JPEG_OPTIMIZE);
|
|
|
- //comprressionParams.push_back(1);
|
|
|
-
|
|
|
- //imwrite(szFileName, testMat, comprressionParams);
|
|
|
- //Resize(szFileName, GetFileSize(szFileName), compatRate);
|
|
|
-
|
|
|
evtPtr->evtStatus = EVTSTATUS_DONE_SUCC;
|
|
|
}
|
|
|
catch(cv::Exception& ex)
|
|
|
{
|
|
|
- Dbg("exception converting image to jpeg: %s", ex.what());
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("exception converting image to jpeg: %s", ex.what());
|
|
|
evtPtr->evtStatus = EVTSTATUS_DONE_FAIL;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
evtPtr->OnAnswer();
|
|
|
}
|
|
|
break;
|
|
@@ -1138,7 +1057,7 @@ bool CDocScannerCap::_executePreview()
|
|
|
}
|
|
|
}
|
|
|
if(m_tpStopPreview) {
|
|
|
- Dbg("Stop previewing event recv.");
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop previewing event recv.");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -1154,7 +1073,6 @@ int CDocScannerCap::GetSpecificedCamInfor(const int camID, PCAMERA_INFOR_ITEM in
|
|
|
return -2;
|
|
|
}
|
|
|
info->Cleanup();
|
|
|
- // Create the System Device Enumerator.
|
|
|
ICreateDevEnum *pSysDevEnum = NULL;
|
|
|
HRESULT hr = CoCreateInstance(
|
|
|
CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
|
|
@@ -1274,11 +1192,7 @@ int CDocScannerCap::_getCamIDByDevName(LPCTSTR lpcszDevName)
|
|
|
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
|
|
|
char szDevName[MAX_PATH + 2] = {0};
|
|
|
int count = 0;
|
|
|
- while( varName.bstrVal[count] != 0x00 && count < MAX_PATH) {
|
|
|
- szDevName[count] = (char)varName.bstrVal[count];
|
|
|
- count++;
|
|
|
- }
|
|
|
- szDevName[count] = 0;
|
|
|
+ WrapW2A(varName, szDevName, MAX_PATH);
|
|
|
if(strcmp(szDevName, lpcszDevName) == 0) {
|
|
|
done = true;
|
|
|
aimID = deviceCounter;
|
|
@@ -1333,14 +1247,14 @@ bool CDocScannerCap::IsColorAbnormal(IplImage* src)
|
|
|
|
|
|
bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
|
|
|
{
|
|
|
- //鍥剧墖姣忚�瀛楄妭鏁板強楂�
|
|
|
+ //图片每行字节数及高
|
|
|
int width=data->widthStep;
|
|
|
int height=data->height;
|
|
|
ushort* sobelTable = new ushort[width*height];
|
|
|
memset(sobelTable, 0, width*height*sizeof(ushort));
|
|
|
|
|
|
int i, j, mul;
|
|
|
- //鎸囧悜鍥惧儚棣栧湴鍧€
|
|
|
+ //指向图像首地址
|
|
|
uchar* udata = (uchar*)data->imageData;
|
|
|
for(i = 1, mul = i*width; i < height - 1; i++, mul += width) {
|
|
|
for(j = 1; j < width - 1; j++) {
|
|
@@ -1361,7 +1275,7 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
|
|
|
|
|
|
uchar suddenThre = 50;
|
|
|
uchar sameThre = 3;
|
|
|
- //閬嶅巻鍥剧墖
|
|
|
+ //遍历图片
|
|
|
for(i = 1, mul = i*width; i < height - 1; i++, mul += width) {
|
|
|
for(j = 1; j < width - 1; j++) {
|
|
|
if(sobelTable[mul+j]) {
|
|
@@ -1464,7 +1378,7 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //妯$硦搴�
|
|
|
+ //模糊度
|
|
|
float result = (float)totLen/totCount;
|
|
|
delete[] sobelTable;
|
|
|
if(result > 5) {
|
|
@@ -1476,7 +1390,6 @@ bool CDocScannerCap::IsFrameFuzzy(IplImage* data)
|
|
|
bool CDocScannerCap::ResetCamera()
|
|
|
{
|
|
|
if(!_isVal() && m_videoID == -1) {
|
|
|
- Dbg("Nothing to do with ResetCamera(%d)", m_videoID);
|
|
|
return true;
|
|
|
}
|
|
|
bool fPreview = m_fPreviewing;
|
|
@@ -1523,7 +1436,7 @@ bool CDocScannerCap::ResetCamera()
|
|
|
m_dwErrCode = ERROR_SUCCESS;
|
|
|
//SetWinShown(m_hideMode != 0 ? false : true);
|
|
|
if(fPreview && !StartPreview()) {
|
|
|
- Dbg("StartPreview failed");
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("StartPreview failed");
|
|
|
return true;
|
|
|
}else if(fPreview && bHide) {
|
|
|
SetWinShown(false);
|
|
@@ -1539,7 +1452,7 @@ int CDocScannerCap::MatResize(const cv::Mat& src, cv::Mat& dest, int quantity)
|
|
|
params.push_back(quantity);
|
|
|
std::vector<unsigned char> buff;
|
|
|
cv::imencode(".jpg", src, buff, params);
|
|
|
- Dbg("after buffer: size: %d, with quantity: %d", buff.size(), quantity);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("after buffer: size: %d, with quantity: %d", buff.size(), quantity);
|
|
|
dest = cv::imdecode(buff, CV_LOAD_IMAGE_COLOR);
|
|
|
if(buff.size() > aim_size)
|
|
|
return (int)(aim_size * 1.2f / buff.size() * 100);
|
|
@@ -1553,7 +1466,7 @@ DWORD CDocScannerCap::GetFileSize(LPCTSTR srcFilePath)
|
|
|
return -1;
|
|
|
fseek(fHandle, 0, SEEK_END);
|
|
|
DWORD fileSize = ftell(fHandle);
|
|
|
- Dbg("get the file size: %lu", fileSize);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get the file size: %lu", fileSize);
|
|
|
fclose(fHandle);
|
|
|
return fileSize;
|
|
|
}
|
|
@@ -1565,7 +1478,7 @@ int CDocScannerCap::ImageWriteUntil(LPCTSTR srcFilePath, const cv::Mat& src)
|
|
|
for(int i=0; i<sizeof(compatRates)/sizeof(compatRates[0]); ++i)
|
|
|
{
|
|
|
const int compatRate = compatRates[i];
|
|
|
- Dbg("set compress rate: %d", compatRate);
|
|
|
+ DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("set compress rate: %d", compatRate);
|
|
|
vector<int> comprressionParams;
|
|
|
comprressionParams.push_back(CV_IMWRITE_JPEG_QUALITY);
|
|
|
comprressionParams.push_back(compatRate);
|
|
@@ -1575,7 +1488,7 @@ int CDocScannerCap::ImageWriteUntil(LPCTSTR srcFilePath, const cv::Mat& src)
|
|
|
|
|
|
} catch(cv::Exception& ex)
|
|
|
{
|
|
|
- Dbg("exception converting image to jpeg: %s", ex.what());
|
|
|
+ DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("exception converting image to jpeg: %s", ex.what());
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
@@ -1599,7 +1512,6 @@ int CDocScannerCap::Resize(LPCTSTR srcFilePath, DWORD dwSrcFileSize, int compres
|
|
|
if(src.empty())
|
|
|
return -1;
|
|
|
float rate = sqrt(aim_size * 1.0f / dwSrcFileSize);
|
|
|
- Dbg("rate: %f", rate);
|
|
|
int width = static_cast<int>(src.cols*rate);
|
|
|
int height = static_cast<int>(src.rows*rate);
|
|
|
|
|
@@ -1616,7 +1528,6 @@ int CDocScannerCap::Resize(LPCTSTR srcFilePath, DWORD dwSrcFileSize, int compres
|
|
|
fseek(fHandle, 0, SEEK_END);
|
|
|
long fileSize = ftell(fHandle);
|
|
|
fclose(fHandle);
|
|
|
- Dbg("get the resize file size: %ld", fileSize);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -1649,7 +1560,6 @@ void OnMouseTrace(int event, int x, int y, int flags, void* param /*= NULL*/)
|
|
|
{
|
|
|
CDocScannerCap* pCap = reinterpret_cast<CDocScannerCap*>(param);
|
|
|
if(pCap == NULL) {
|
|
|
- Dbg("OnMouseTest::param is NULL!");
|
|
|
return;
|
|
|
}
|
|
|
pCap->MouseClick(event, x, y, flags);
|