Merge pull request 'update' (#7) from develop into master
@ -0,0 +1,44 @@
|
|||||||
|
.idea/
|
||||||
|
_build/
|
||||||
|
resources/image/tmp/
|
||||||
|
*.lib
|
||||||
|
*.suo
|
||||||
|
*.sdf
|
||||||
|
*.opensdf
|
||||||
|
*.exe
|
||||||
|
*.dll
|
||||||
|
*.ilk
|
||||||
|
*.pdb
|
||||||
|
experi
|
||||||
|
/tmp
|
||||||
|
resources/image/native_test/*.jpg
|
||||||
|
resources/image/native_test/cars
|
||||||
|
resources/image/native_test/*.py
|
||||||
|
resources/image/phone_test
|
||||||
|
*.vsp
|
||||||
|
*.psess
|
||||||
|
*.DS_Store
|
||||||
|
#ignore thumbnails created by windows
|
||||||
|
Thumbs.db
|
||||||
|
#Ignore files build by Visual Studio
|
||||||
|
*.user
|
||||||
|
*.aps
|
||||||
|
*.pch
|
||||||
|
*.vspscc
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*.ncb
|
||||||
|
*.tlb
|
||||||
|
*.tlh
|
||||||
|
*.bak
|
||||||
|
[Dd]ebug*/
|
||||||
|
*.sbr
|
||||||
|
obj/
|
||||||
|
[Rr]elease*/
|
||||||
|
_ReSharper*/
|
||||||
|
[Tt]est[Rr]esult*
|
||||||
|
|
||||||
|
*.obj
|
||||||
|
*.cache
|
||||||
|
*.log
|
||||||
|
|
@ -0,0 +1,64 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.0.0)
|
||||||
|
project(easypr)
|
||||||
|
|
||||||
|
# c++11 required
|
||||||
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||||
|
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/opt/opencv-3.2.0")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# OpenVC3 required
|
||||||
|
find_package(OpenCV 3.2.0 REQUIRED)
|
||||||
|
|
||||||
|
# where to find header files
|
||||||
|
include_directories(.)
|
||||||
|
include_directories(include)
|
||||||
|
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# sub directories
|
||||||
|
add_subdirectory(thirdparty)
|
||||||
|
|
||||||
|
# sources to be compiled
|
||||||
|
set(SOURCE_FILES
|
||||||
|
src/core/core_func.cpp
|
||||||
|
src/core/chars_identify.cpp
|
||||||
|
src/core/chars_recognise.cpp
|
||||||
|
src/core/chars_segment.cpp
|
||||||
|
src/core/feature.cpp
|
||||||
|
src/core/plate_detect.cpp
|
||||||
|
src/core/plate_judge.cpp
|
||||||
|
src/core/plate_locate.cpp
|
||||||
|
src/core/plate_recognize.cpp
|
||||||
|
src/core/params.cpp
|
||||||
|
|
||||||
|
src/train/ann_train.cpp
|
||||||
|
src/train/annCh_train.cpp
|
||||||
|
src/train/svm_train.cpp
|
||||||
|
src/train/train.cpp
|
||||||
|
src/train/create_data.cpp
|
||||||
|
|
||||||
|
src/util/util.cpp
|
||||||
|
src/util/program_options.cpp
|
||||||
|
src/util/kv.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# pack objects to static library
|
||||||
|
add_library(easypr STATIC ${SOURCE_FILES})
|
||||||
|
|
||||||
|
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||||
|
set(EXECUTABLE_NAME "demo")
|
||||||
|
elseif (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||||
|
set(EXECUTABLE_NAME "demo")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
# set to be releas mode
|
||||||
|
# set(CMAKE_BUILD_TYPE Release)
|
||||||
|
|
||||||
|
# test cases
|
||||||
|
add_executable(${EXECUTABLE_NAME} test/main.cpp)
|
||||||
|
# link opencv libs
|
||||||
|
target_link_libraries(${EXECUTABLE_NAME} easypr thirdparty ${OpenCV_LIBS})
|
||||||
|
# MESSAGE(${CMAKE_BINARY_DIR}/../)
|
||||||
|
SET_TARGET_PROPERTIES(${EXECUTABLE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/../")
|
@ -0,0 +1,202 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
@ -1,679 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* FileName : CatchScreenDlg.cpp
|
|
||||||
* Author : Unknown
|
|
||||||
* Mender : sudami
|
|
||||||
* Time : 2007/09/09
|
|
||||||
*
|
|
||||||
* Comment :
|
|
||||||
*
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "Screenshot.h"
|
|
||||||
#include "CatchScreenDlg.h"
|
|
||||||
|
|
||||||
#include <GdiPlus.h>
|
|
||||||
using namespace Gdiplus;
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define new DEBUG_NEW
|
|
||||||
#undef THIS_FILE
|
|
||||||
static char THIS_FILE[] = __FILE__;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// CCatchScreenDlg dialog
|
|
||||||
|
|
||||||
CCatchScreenDlg::CCatchScreenDlg(CWnd* pParent /*=NULL*/)
|
|
||||||
: CDialog(CCatchScreenDlg::IDD, pParent)
|
|
||||||
{
|
|
||||||
m_bLBtnDown = FALSE;
|
|
||||||
//初始化像皮筋类,新增的resizeMiddle 类型
|
|
||||||
m_rectTracker.m_nStyle = CMyTracker::resizeMiddle | CMyTracker::solidLine;
|
|
||||||
m_rectTracker.m_rect.SetRect(-1, -2, -3, -4);
|
|
||||||
//设置矩形颜色
|
|
||||||
m_rectTracker.SetRectColor(RGB(10, 100, 130));
|
|
||||||
|
|
||||||
m_hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR1);
|
|
||||||
|
|
||||||
m_bDraw = FALSE;
|
|
||||||
m_bFirstDraw = FALSE;
|
|
||||||
m_bQuit = FALSE;
|
|
||||||
m_bNeedShowMsg = FALSE;
|
|
||||||
m_startPt = 0;
|
|
||||||
|
|
||||||
//获取屏幕分辩率
|
|
||||||
m_xScreen = GetSystemMetrics(SM_CXSCREEN);
|
|
||||||
m_yScreen = GetSystemMetrics(SM_CYSCREEN);
|
|
||||||
|
|
||||||
//截取屏幕到位图中
|
|
||||||
CRect rect(0, 0, m_xScreen, m_yScreen);
|
|
||||||
m_hBitmap = CopyScreenToBitmap(&rect);
|
|
||||||
m_pBitmap = CBitmap::FromHandle(m_hBitmap);
|
|
||||||
|
|
||||||
//初始化刷新窗口区域 m_rgn
|
|
||||||
m_rgn.CreateRectRgn(0, 0, 50, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::DoDataExchange(CDataExchange* pDX)
|
|
||||||
{
|
|
||||||
CDialog::DoDataExchange(pDX);
|
|
||||||
DDX_Control(pDX, IDC_EDIT1, m_tipEdit);
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CCatchScreenDlg, CDialog)
|
|
||||||
ON_WM_PAINT()
|
|
||||||
ON_WM_MOUSEMOVE()
|
|
||||||
ON_WM_LBUTTONDOWN()
|
|
||||||
ON_WM_LBUTTONUP()
|
|
||||||
ON_WM_LBUTTONDBLCLK()
|
|
||||||
ON_WM_ERASEBKGND()
|
|
||||||
ON_WM_SETCURSOR()
|
|
||||||
ON_WM_RBUTTONUP()
|
|
||||||
ON_WM_CTLCOLOR()
|
|
||||||
ON_WM_RBUTTONDOWN()
|
|
||||||
END_MESSAGE_MAP()
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CCatchScreenDlg message handlers
|
|
||||||
|
|
||||||
BOOL CCatchScreenDlg::OnInitDialog()
|
|
||||||
{
|
|
||||||
CDialog::OnInitDialog();
|
|
||||||
//把对化框设置成全屏顶层窗口
|
|
||||||
SetWindowPos(&wndTopMost, 0, 0, m_xScreen, m_yScreen, SWP_SHOWWINDOW);
|
|
||||||
|
|
||||||
//移动操作提示窗口
|
|
||||||
CRect rect;
|
|
||||||
m_tipEdit.GetWindowRect(&rect);
|
|
||||||
m_tipEdit.MoveWindow(10, 10, rect.Width(), rect.Height());
|
|
||||||
|
|
||||||
|
|
||||||
m_toolBar.CreateToolBar(m_hWnd);
|
|
||||||
m_toolBar.RemoveChildStyle();
|
|
||||||
::MoveWindow(m_toolBar.GetHWND(),300,300,230,30,FALSE);
|
|
||||||
|
|
||||||
|
|
||||||
UpdateTipString();
|
|
||||||
SetEidtWndText();
|
|
||||||
|
|
||||||
((CScreenshotApp *)AfxGetApp())->m_hwndDlg = AfxGetMainWnd()->GetSafeHwnd();
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnPaint()
|
|
||||||
{
|
|
||||||
// 如果窗口是最小化状态
|
|
||||||
if (IsIconic())
|
|
||||||
{
|
|
||||||
CPaintDC dc(this);
|
|
||||||
|
|
||||||
SendMessage(WM_ICONERASEBKGND, (WPARAM)dc.GetSafeHdc(), 0);
|
|
||||||
|
|
||||||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
|
||||||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
|
||||||
CRect rect;
|
|
||||||
GetClientRect(&rect);
|
|
||||||
int x = (rect.Width() - cxIcon + 1) / 2;
|
|
||||||
int y = (rect.Height() - cyIcon + 1) / 2;
|
|
||||||
|
|
||||||
}
|
|
||||||
else // 如果窗口正常显示
|
|
||||||
{
|
|
||||||
CPaintDC dc(this);
|
|
||||||
|
|
||||||
CDC dcCompatible;
|
|
||||||
|
|
||||||
dcCompatible.CreateCompatibleDC(&dc);
|
|
||||||
RECT rect;
|
|
||||||
::GetClientRect(m_hWnd, &rect);
|
|
||||||
HBITMAP hBitmap = ::CreateCompatibleBitmap(dc.m_hDC,rect.right-rect.left,rect.bottom-rect.top);
|
|
||||||
::SelectObject(dcCompatible.m_hDC,hBitmap);
|
|
||||||
|
|
||||||
HBRUSH s_hBitmapBrush = CreatePatternBrush(m_hBitmap);
|
|
||||||
::FillRect(dcCompatible.m_hDC,&rect,s_hBitmapBrush);
|
|
||||||
|
|
||||||
//显示截取矩形大小信息
|
|
||||||
if (m_bNeedShowMsg && m_bFirstDraw)
|
|
||||||
{
|
|
||||||
CRect rect = m_rectTracker.m_rect;
|
|
||||||
DrawMessage(rect, &dcCompatible);
|
|
||||||
}
|
|
||||||
|
|
||||||
//画出像皮筋矩形
|
|
||||||
if (m_bFirstDraw)
|
|
||||||
{
|
|
||||||
m_rectTracker.Draw(&dcCompatible);
|
|
||||||
}
|
|
||||||
Gdiplus::Graphics graphics(dcCompatible);
|
|
||||||
|
|
||||||
HRGN hgn1 = CreateRectRgn(m_rectTracker.m_rect.left,m_rectTracker.m_rect.top,
|
|
||||||
m_rectTracker.m_rect.right,m_rectTracker.m_rect.bottom);
|
|
||||||
Region region1(hgn1);
|
|
||||||
|
|
||||||
HRGN hgn2 = CreateRectRgn(rect.left,rect.top,
|
|
||||||
rect.right,rect.bottom);
|
|
||||||
Region region2(hgn2);
|
|
||||||
|
|
||||||
region2.Exclude(®ion1);
|
|
||||||
|
|
||||||
SolidBrush solidBrush(Color(100, 128, 128, 128));
|
|
||||||
graphics.FillRegion(&solidBrush,®ion2);
|
|
||||||
|
|
||||||
DeleteObject(hgn1);
|
|
||||||
DeleteObject(hgn2);
|
|
||||||
|
|
||||||
dc.BitBlt(0,0,rect.right, rect.bottom,&dcCompatible,0,0,SRCCOPY);
|
|
||||||
DeleteObject(hBitmap);
|
|
||||||
DeleteObject(s_hBitmapBrush);
|
|
||||||
|
|
||||||
//CDialog::OnPaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnCancel()
|
|
||||||
{
|
|
||||||
if (m_bFirstDraw)
|
|
||||||
{
|
|
||||||
//取消已画矩形变量
|
|
||||||
m_bFirstDraw = FALSE;
|
|
||||||
m_bDraw = FALSE;
|
|
||||||
m_rectTracker.m_rect.SetRect(-1, -1, -1, -1);
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CDialog::OnCancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnMouseMove(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
if(m_bLBtnDown)
|
|
||||||
m_toolBar.HideToolBar();
|
|
||||||
else
|
|
||||||
m_toolBar.ShowToolBar();
|
|
||||||
if (m_bDraw)
|
|
||||||
{
|
|
||||||
//动态调整矩形大小,并刷新画出
|
|
||||||
m_rectTracker.m_rect.SetRect(m_startPt.x + 4, m_startPt.y + 4, point.x, point.y);
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
//弥补调整大小和位置时,接收不到MouseMove消息
|
|
||||||
CRect rect;
|
|
||||||
m_tipEdit.GetWindowRect(&rect);
|
|
||||||
if (rect.PtInRect(point))
|
|
||||||
m_tipEdit.SendMessage(WM_MOUSEMOVE);
|
|
||||||
|
|
||||||
UpdateMousePointRGBString();
|
|
||||||
SetEidtWndText();
|
|
||||||
|
|
||||||
CDialog::OnMouseMove(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnLButtonDown(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
m_bLBtnDown = TRUE;
|
|
||||||
int nHitTest;
|
|
||||||
nHitTest = m_rectTracker.HitTest(point);
|
|
||||||
//判断击中位置
|
|
||||||
if (nHitTest < 0)
|
|
||||||
{
|
|
||||||
if (!m_bFirstDraw)
|
|
||||||
{
|
|
||||||
//第一次画矩形
|
|
||||||
m_startPt = point;
|
|
||||||
m_bDraw = TRUE;
|
|
||||||
m_bFirstDraw = TRUE;
|
|
||||||
//设置当鼠标按下时最小的矩形大小
|
|
||||||
m_rectTracker.m_rect.SetRect(point.x, point.y, point.x + 4, point.y + 4);
|
|
||||||
|
|
||||||
//保证当鼠标当下时立刻显示信息
|
|
||||||
if (m_bFirstDraw)
|
|
||||||
m_bNeedShowMsg = TRUE;
|
|
||||||
UpdateTipString();
|
|
||||||
SetEidtWndText();
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//保证当鼠标当下时立刻显示信息
|
|
||||||
m_bNeedShowMsg = TRUE;
|
|
||||||
if (m_bFirstDraw)
|
|
||||||
{
|
|
||||||
//调束大小时,Track会自动调整矩形大小,在些期间,消息归CRectTracker内部处理
|
|
||||||
m_rectTracker.Track(this, point, TRUE);
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CDialog::OnLButtonDown(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnLButtonUp(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
m_bLBtnDown = FALSE;
|
|
||||||
m_bNeedShowMsg = FALSE;
|
|
||||||
m_bDraw = FALSE;
|
|
||||||
UpdateTipString();
|
|
||||||
SetEidtWndText();
|
|
||||||
m_toolBar.SetShowPlace(m_rectTracker.m_rect.right,m_rectTracker.m_rect.bottom);
|
|
||||||
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
CDialog::OnLButtonUp(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnLButtonDblClk(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
int nHitTest;
|
|
||||||
nHitTest = m_rectTracker.HitTest(point);
|
|
||||||
|
|
||||||
//如果在是矩形内部双击
|
|
||||||
if (nHitTest == 8)
|
|
||||||
{
|
|
||||||
//保存位图到粘贴板中,bSave 为TRUE,
|
|
||||||
CopyScreenToBitmap(m_rectTracker.m_rect, TRUE);
|
|
||||||
PostQuitMessage(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
CDialog::OnLButtonDblClk(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnRButtonDown(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
m_toolBar.HideToolBar();
|
|
||||||
//InvalidateRgnWindow();
|
|
||||||
CDialog::OnRButtonDown(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::OnRButtonUp(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
m_bLBtnDown = FALSE;
|
|
||||||
if (m_bFirstDraw)
|
|
||||||
{
|
|
||||||
//如果已经截取矩则清除截取矩形
|
|
||||||
m_bFirstDraw = FALSE;
|
|
||||||
//清除矩形大小
|
|
||||||
m_rectTracker.m_rect.SetRect(-1, -1, -1, -1);
|
|
||||||
UpdateTipString();
|
|
||||||
SetEidtWndText();
|
|
||||||
InvalidateRgnWindow();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//关闭程序
|
|
||||||
PostQuitMessage(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
CDialog::OnRButtonUp(nFlags, point);
|
|
||||||
}
|
|
||||||
|
|
||||||
HBRUSH CCatchScreenDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
|
||||||
{
|
|
||||||
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
||||||
|
|
||||||
//设置操作提示窗口文本颜色
|
|
||||||
if (pWnd->GetDlgCtrlID() == IDC_EDIT1)
|
|
||||||
{
|
|
||||||
pDC->SetTextColor(RGB(247,76,128));
|
|
||||||
}
|
|
||||||
|
|
||||||
return hbr;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CCatchScreenDlg::OnEraseBkgnd(CDC* pDC)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
//用整个桌面填充全屏对话框背景
|
|
||||||
BITMAP bmp;
|
|
||||||
m_pBitmap->GetBitmap(&bmp);
|
|
||||||
|
|
||||||
CDC dcCompatible;
|
|
||||||
dcCompatible.CreateCompatibleDC(pDC);
|
|
||||||
|
|
||||||
dcCompatible.SelectObject(m_pBitmap);
|
|
||||||
|
|
||||||
CRect rect;
|
|
||||||
GetClientRect(&rect);
|
|
||||||
pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &dcCompatible, 0, 0, SRCCOPY);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CCatchScreenDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
||||||
{
|
|
||||||
//设置改变截取矩形大小时光标
|
|
||||||
if (pWnd == this &&m_rectTracker.SetCursor(this, nHitTest)
|
|
||||||
&& !m_bDraw &&m_bFirstDraw) //此处判断保截取时当标始中为彩色光标
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//设置彩色光标
|
|
||||||
SetCursor(m_hCursor);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拷贝屏幕, 这段源码源自CSDN
|
|
||||||
// lpRect 代表选定区域
|
|
||||||
HBITMAP CCatchScreenDlg::CopyScreenToBitmap(LPRECT lpRect, BOOL bSave)
|
|
||||||
|
|
||||||
{
|
|
||||||
HDC hScrDC, hMemDC;
|
|
||||||
// 屏幕和内存设备描述表
|
|
||||||
HBITMAP hBitmap, hOldBitmap;
|
|
||||||
// 位图句柄
|
|
||||||
int nX, nY, nX2, nY2;
|
|
||||||
// 选定区域坐标
|
|
||||||
int nWidth, nHeight;
|
|
||||||
|
|
||||||
// 确保选定区域不为空矩形
|
|
||||||
if (IsRectEmpty(lpRect))
|
|
||||||
return NULL;
|
|
||||||
//为屏幕创建设备描述表
|
|
||||||
hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
|
|
||||||
|
|
||||||
//为屏幕设备描述表创建兼容的内存设备描述表
|
|
||||||
hMemDC = CreateCompatibleDC(hScrDC);
|
|
||||||
// 获得选定区域坐标
|
|
||||||
nX = lpRect->left;
|
|
||||||
nY = lpRect->top;
|
|
||||||
nX2 = lpRect->right;
|
|
||||||
nY2 = lpRect->bottom;
|
|
||||||
|
|
||||||
//确保选定区域是可见的
|
|
||||||
if (nX < 0)
|
|
||||||
nX = 0;
|
|
||||||
if (nY < 0)
|
|
||||||
nY = 0;
|
|
||||||
if (nX2 > m_xScreen)
|
|
||||||
nX2 = m_xScreen;
|
|
||||||
if (nY2 > m_yScreen)
|
|
||||||
nY2 = m_yScreen;
|
|
||||||
nWidth = nX2 - nX;
|
|
||||||
nHeight = nY2 - nY;
|
|
||||||
// 创建一个与屏幕设备描述表兼容的位图
|
|
||||||
hBitmap = CreateCompatibleBitmap
|
|
||||||
(hScrDC, nWidth, nHeight);
|
|
||||||
// 把新位图选到内存设备描述表中
|
|
||||||
hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
|
|
||||||
// 把屏幕设备描述表拷贝到内存设备描述表中
|
|
||||||
if (bSave)
|
|
||||||
{
|
|
||||||
//创建兼容DC,当bSave为中时把开始保存的全屏位图,按截取矩形大小保存
|
|
||||||
CDC dcCompatible;
|
|
||||||
dcCompatible.CreateCompatibleDC(CDC::FromHandle(hMemDC));
|
|
||||||
dcCompatible.SelectObject(m_pBitmap);
|
|
||||||
|
|
||||||
BitBlt(hMemDC, 0, 0, nWidth, nHeight,
|
|
||||||
dcCompatible, nX, nY, SRCCOPY);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BitBlt(hMemDC, 0, 0, nWidth, nHeight,
|
|
||||||
hScrDC, nX, nY, SRCCOPY);
|
|
||||||
}
|
|
||||||
|
|
||||||
hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
|
|
||||||
//得到屏幕位图的句柄
|
|
||||||
//清除
|
|
||||||
DeleteDC(hScrDC);
|
|
||||||
DeleteDC(hMemDC);
|
|
||||||
|
|
||||||
if (bSave)
|
|
||||||
{
|
|
||||||
if (OpenClipboard())
|
|
||||||
{
|
|
||||||
//清空剪贴板
|
|
||||||
EmptyClipboard();
|
|
||||||
//把屏幕内容粘贴到剪贴板上,
|
|
||||||
//hBitmap 为刚才的屏幕位图句柄
|
|
||||||
SetClipboardData(CF_BITMAP, hBitmap);
|
|
||||||
//关闭剪贴板
|
|
||||||
CloseClipboard();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 返回位图句柄
|
|
||||||
return hBitmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示操作提示信息
|
|
||||||
void CCatchScreenDlg::UpdateTipString()
|
|
||||||
{
|
|
||||||
CString strTemp;
|
|
||||||
if (!m_bDraw && !m_bFirstDraw)
|
|
||||||
{
|
|
||||||
strTemp = _T("\r\n\r\n·按下鼠标左键不放选择截取\r\n\r\n·ESC键、鼠标右键退出");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (m_bDraw && m_bFirstDraw)
|
|
||||||
{
|
|
||||||
strTemp = _T("\r\n\r\n·松开鼠标左键确定截取范围\r\n\r\n·ESC键退出");
|
|
||||||
}
|
|
||||||
else if (!m_bDraw && m_bFirstDraw)
|
|
||||||
{
|
|
||||||
CString sudami(_T("\r\n\r\n·矩形内双击鼠标左键保存\r\n\r\n·点击鼠标右键重新选择"));
|
|
||||||
strTemp = _T("\r\n\r\n·鼠标在矩形边缘调整大小");
|
|
||||||
|
|
||||||
strTemp += sudami;
|
|
||||||
}
|
|
||||||
m_strEditTip = strTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 显示截取矩形信息
|
|
||||||
void CCatchScreenDlg::DrawMessage(CRect &inRect, CDC * pDC)
|
|
||||||
{
|
|
||||||
//截取矩形大小信息离鼠标间隔
|
|
||||||
const int space = 3;
|
|
||||||
|
|
||||||
//设置字体颜色大小
|
|
||||||
CPoint pt;
|
|
||||||
CPen pen(PS_SOLID, 1, RGB(47, 79, 79));
|
|
||||||
CPen *pOldPen;
|
|
||||||
pOldPen = pDC->SelectObject(&pen);
|
|
||||||
|
|
||||||
//pDC->SetTextColor(RGB(147,147,147));
|
|
||||||
CFont font;
|
|
||||||
CFont * pOldFont;
|
|
||||||
font.CreatePointFont(90, _T("宋体"));
|
|
||||||
pOldFont = pDC->SelectObject(&font);
|
|
||||||
|
|
||||||
//得到字体宽度和高度
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
int OldBkMode;
|
|
||||||
OldBkMode = pDC->SetBkMode(TRANSPARENT);
|
|
||||||
|
|
||||||
TEXTMETRIC tm;
|
|
||||||
int charHeight;
|
|
||||||
CSize size;
|
|
||||||
int lineLength;
|
|
||||||
pDC->GetTextMetrics(&tm);
|
|
||||||
charHeight = tm.tmHeight + tm.tmExternalLeading;
|
|
||||||
size = pDC->GetTextExtent(_T("顶点位置 "), _tcslen(_T("顶点位置 ")));
|
|
||||||
lineLength = size.cx;
|
|
||||||
|
|
||||||
//初始化矩形, 以保证写下六行文字
|
|
||||||
CRect rect(pt.x + space, pt.y - charHeight * 6 - space, pt.x + lineLength + space, pt.y - space);
|
|
||||||
|
|
||||||
//创建临时矩形
|
|
||||||
CRect rectTemp;
|
|
||||||
//当矩形到达桌面边缘时调整方向和大小
|
|
||||||
if ((pt.x + rect.Width()) >= m_xScreen)
|
|
||||||
{
|
|
||||||
//桌面上方显示不下矩形
|
|
||||||
rectTemp = rect;
|
|
||||||
rectTemp.left = rect.left - rect.Width() - space * 2;
|
|
||||||
rectTemp.right = rect.right - rect.Width() - space * 2;;
|
|
||||||
rect = rectTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((pt.y - rect.Height()) <= 0)
|
|
||||||
{
|
|
||||||
//桌面右方显示不下矩形
|
|
||||||
rectTemp = rect;
|
|
||||||
rectTemp.top = rect.top + rect.Height() + space * 2;;
|
|
||||||
rectTemp.bottom = rect.bottom + rect.Height() + space * 2;;
|
|
||||||
rect = rectTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//创建空画刷画矩形
|
|
||||||
CBrush * pOldBrush;
|
|
||||||
pOldBrush = pDC->SelectObject(CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)));
|
|
||||||
|
|
||||||
pDC->Rectangle(rect);
|
|
||||||
rect.top += 2;
|
|
||||||
//在矩形中显示文字
|
|
||||||
CRect outRect(rect.left, rect.top, rect.left + lineLength, rect.top + charHeight);
|
|
||||||
CString string(_T("顶点位置"));
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
outRect.SetRect(rect.left, rect.top + charHeight, rect.left + lineLength, charHeight + rect.top + charHeight);
|
|
||||||
string.Format(_T("(%d,%d)"), inRect.left, inRect.top);
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
|
|
||||||
outRect.SetRect(rect.left, rect.top + charHeight * 2, rect.left + lineLength, charHeight + rect.top + charHeight * 2);
|
|
||||||
string = _T("矩形大小");
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
outRect.SetRect(rect.left, rect.top + charHeight * 3, rect.left + lineLength, charHeight + rect.top + charHeight * 3);
|
|
||||||
string.Format(_T("(%d,%d)"), inRect.Width(), inRect.Height());
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
outRect.SetRect(rect.left, rect.top + charHeight * 4, rect.left + lineLength, charHeight + rect.top + charHeight * 4);
|
|
||||||
string = _T("光标坐标");
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
outRect.SetRect(rect.left, rect.top + charHeight * 5, rect.left + lineLength, charHeight + rect.top + charHeight * 5);
|
|
||||||
string.Format(_T("(%d,%d)"), pt.x, pt.y);
|
|
||||||
pDC->DrawText(string, outRect, DT_CENTER);
|
|
||||||
|
|
||||||
pDC->SetBkMode(OldBkMode);
|
|
||||||
pDC->SelectObject(pOldFont);
|
|
||||||
pDC->SelectObject(pOldBrush);
|
|
||||||
pDC->SelectObject(pOldPen);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 刷新局部窗口
|
|
||||||
void CCatchScreenDlg::InvalidateRgnWindow()
|
|
||||||
{
|
|
||||||
//获取当全屏对话框窗口大小
|
|
||||||
CRect rect1;
|
|
||||||
GetWindowRect(rect1);
|
|
||||||
|
|
||||||
//获取编辑框窗口大小
|
|
||||||
CRect rect2;
|
|
||||||
m_tipEdit.GetWindowRect(rect2);
|
|
||||||
|
|
||||||
CRgn rgn1, rgn2;
|
|
||||||
rgn1.CreateRectRgnIndirect(rect1);
|
|
||||||
rgn2.CreateRectRgnIndirect(rect2);
|
|
||||||
|
|
||||||
//获取更新区域,就是除了编辑框窗口不更新
|
|
||||||
//m_rgn.CombineRgn(&rgn1, &rgn2, RGN_DIFF);
|
|
||||||
|
|
||||||
// 添加ToolBar不刷新
|
|
||||||
CRect rect3;
|
|
||||||
::GetWindowRect(m_toolBar.GetHWND(),&rect3);
|
|
||||||
CRgn rgn3;
|
|
||||||
rgn3.CreateRectRgnIndirect(rect3);
|
|
||||||
|
|
||||||
CRgn rgnTemp;
|
|
||||||
rgnTemp.CreateRectRgn(0, 0, 50, 50);
|
|
||||||
rgnTemp.CombineRgn(&rgn1, &rgn2, RGN_DIFF);
|
|
||||||
m_rgn.CombineRgn(&rgnTemp, &rgn3, RGN_DIFF);
|
|
||||||
|
|
||||||
InvalidateRgn(&m_rgn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::UpdateMousePointRGBString()
|
|
||||||
{
|
|
||||||
static CString strOld("");
|
|
||||||
|
|
||||||
CPoint pt;
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
|
|
||||||
COLORREF color;
|
|
||||||
CClientDC dc(this);
|
|
||||||
color = dc.GetPixel(pt);
|
|
||||||
BYTE rValue, gValue, bValue;
|
|
||||||
rValue = GetRValue(color);
|
|
||||||
gValue = GetGValue(color);
|
|
||||||
bValue = GetGValue(color);
|
|
||||||
|
|
||||||
//按格式排放字符串
|
|
||||||
CString string;
|
|
||||||
string.Format(_T("\r\n\r\n·当前像素RGB(%d,%d,%d)"), rValue, gValue, bValue);
|
|
||||||
|
|
||||||
//如果当前颜色没变则不刷新RGB值,以免窗口有更多闪烁
|
|
||||||
if (strOld != string)
|
|
||||||
{
|
|
||||||
m_strRgb = string;
|
|
||||||
}
|
|
||||||
strOld = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCatchScreenDlg::SetEidtWndText()
|
|
||||||
{
|
|
||||||
m_tipEdit.SetWindowText(this->GetEditText());
|
|
||||||
}
|
|
||||||
|
|
||||||
CString CCatchScreenDlg::GetEditText()
|
|
||||||
{
|
|
||||||
CString str;
|
|
||||||
str.Append(m_strRgb);
|
|
||||||
str.Append(m_strEditTip);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CCatchScreenDlg::OnCommand(WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
bool bHandle = true;
|
|
||||||
HWND hWnd = m_toolBar.GetHWND();
|
|
||||||
if(lParam == (LPARAM)m_toolBar.GetHWND())
|
|
||||||
{
|
|
||||||
int wmId = LOWORD(wParam);
|
|
||||||
switch(wmId)
|
|
||||||
{
|
|
||||||
case MyToolBar_ID:
|
|
||||||
AfxMessageBox(_T("矩形"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID+1:
|
|
||||||
AfxMessageBox(_T("圆形"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +2:
|
|
||||||
AfxMessageBox(_T("画笔"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +3:
|
|
||||||
AfxMessageBox(_T("马赛克"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +4:
|
|
||||||
AfxMessageBox(_T("文字"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +5:
|
|
||||||
AfxMessageBox(_T("撤销"));
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +6:
|
|
||||||
CopyScreenToBitmap(m_rectTracker.m_rect, TRUE);
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +7:
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
|
||||||
case MyToolBar_ID +8:
|
|
||||||
CopyScreenToBitmap(m_rectTracker.m_rect, TRUE);
|
|
||||||
PostQuitMessage(0);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
bHandle = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
::SetFocus(hWnd);
|
|
||||||
}
|
|
||||||
if (bHandle == false)
|
|
||||||
{
|
|
||||||
return CDialog::OnCommand(wParam,lParam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////// END OF FILE ///////////////////////////////////////
|
|
@ -1,90 +0,0 @@
|
|||||||
#if !defined(AFX_CATCHSCREENDLG_H__536FDBC8_7DB2_4BEF_8943_70DBE8AD845F__INCLUDED_)
|
|
||||||
#define AFX_CATCHSCREENDLG_H__536FDBC8_7DB2_4BEF_8943_70DBE8AD845F__INCLUDED_
|
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
#include "Resource.h"
|
|
||||||
#include "MyEdit.h"
|
|
||||||
|
|
||||||
#ifndef MYTRACKER_
|
|
||||||
#include "MyTracker.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "MyToolBar.h"
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
class CCatchScreenDlg : public CDialog
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
CCatchScreenDlg(CWnd* pParent = NULL);
|
|
||||||
|
|
||||||
enum { IDD = IDD_DIALOGFORIMG };
|
|
||||||
CMyEdit m_tipEdit;
|
|
||||||
CMyToolBar m_toolBar;
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
int m_xScreen;
|
|
||||||
int m_yScreen;
|
|
||||||
|
|
||||||
|
|
||||||
BOOL m_bLBtnDown;
|
|
||||||
|
|
||||||
BOOL m_bNeedShowMsg; // 显示截取矩形大小信息
|
|
||||||
BOOL m_bDraw; // 是否为截取状态
|
|
||||||
BOOL m_bFirstDraw; // 是否为首次截取
|
|
||||||
BOOL m_bQuit; // 是否为退出
|
|
||||||
CPoint m_startPt; // 截取矩形左上角位置
|
|
||||||
|
|
||||||
CMyTracker m_rectTracker; // 像皮筋类
|
|
||||||
CBrush m_brush;
|
|
||||||
HCURSOR m_hCursor; // 光标
|
|
||||||
CBitmap* m_pBitmap; // Edit关联控件的背景位图
|
|
||||||
HBITMAP m_hBitmap;
|
|
||||||
|
|
||||||
CRgn m_rgn; // 背景擦除区域
|
|
||||||
|
|
||||||
public:
|
|
||||||
HBITMAP CopyScreenToBitmap(LPRECT lpRect,BOOL bSave=FALSE); /* 拷贝桌面到位图 */
|
|
||||||
void UpdateTipString(); //显示操作提示信息
|
|
||||||
void DrawMessage(CRect &inRect,CDC * pDC); //显示截取矩形信息
|
|
||||||
void InvalidateRgnWindow(); //重画窗口
|
|
||||||
void UpdateMousePointRGBString();
|
|
||||||
|
|
||||||
CString m_strRgb;
|
|
||||||
CString m_strEditTip;
|
|
||||||
|
|
||||||
void SetEidtWndText();
|
|
||||||
CString GetEditText();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void DoDataExchange(CDataExchange* pDX);
|
|
||||||
virtual BOOL OnInitDialog();
|
|
||||||
virtual void OnCancel();
|
|
||||||
|
|
||||||
afx_msg void OnPaint();
|
|
||||||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
|
||||||
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
|
|
||||||
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
|
|
||||||
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
|
|
||||||
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
|
|
||||||
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
|
|
||||||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
|
||||||
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
|
|
||||||
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
|
|
||||||
|
|
||||||
|
|
||||||
DECLARE_MESSAGE_MAP()
|
|
||||||
|
|
||||||
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,120 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* FileName : MyEdit.CPP
|
|
||||||
* Author : Unknown
|
|
||||||
* Mender : sudami
|
|
||||||
* Time : 2007/09/09
|
|
||||||
*
|
|
||||||
* Comment :
|
|
||||||
*--------------------------------------------------------
|
|
||||||
* 截图程序中的一个控件封装类.
|
|
||||||
* 将控件和该类关联后,可以显示出当前截图的一些提示信息
|
|
||||||
*--------------------------------------------------------
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "MyEdit.h"
|
|
||||||
#include "resource.h"
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 构造函数、析构函数
|
|
||||||
//
|
|
||||||
CMyEdit::CMyEdit()
|
|
||||||
{
|
|
||||||
m_bMove=TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMyEdit::~CMyEdit()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
|
|
||||||
/* 2个小消息 */
|
|
||||||
ON_WM_CREATE()
|
|
||||||
ON_WM_PAINT()
|
|
||||||
ON_WM_SETFOCUS()
|
|
||||||
/* 3个大消息 */
|
|
||||||
ON_WM_MOUSEMOVE()
|
|
||||||
ON_WM_ERASEBKGND()
|
|
||||||
END_MESSAGE_MAP()
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
int CMyEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
||||||
{
|
|
||||||
if (CEdit::OnCreate(lpCreateStruct) == -1)
|
|
||||||
return -1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void CMyEdit::OnPaint()
|
|
||||||
{
|
|
||||||
CPaintDC dc(this);
|
|
||||||
|
|
||||||
CDC dcCompatible;
|
|
||||||
dcCompatible.CreateCompatibleDC(&dc);
|
|
||||||
|
|
||||||
dcCompatible.SetBkMode(TRANSPARENT);
|
|
||||||
CBitmap bitmap;
|
|
||||||
bitmap.LoadBitmap(IDB_BITMAP_BK);
|
|
||||||
dcCompatible.SelectObject(&bitmap);
|
|
||||||
|
|
||||||
RECT rt = {5,5,0,0};
|
|
||||||
RECT rtClient = {0};
|
|
||||||
GetClientRect(&rtClient);
|
|
||||||
rt.right = rtClient.right;
|
|
||||||
rt.bottom = rtClient.bottom;
|
|
||||||
|
|
||||||
CString str;
|
|
||||||
GetWindowText(str);
|
|
||||||
CFont font;
|
|
||||||
CFont * pOldFont;
|
|
||||||
font.CreatePointFont(90, _T("宋体"));
|
|
||||||
pOldFont = dcCompatible.SelectObject(&font);
|
|
||||||
dcCompatible.DrawText(str,&rt,DT_LEFT);
|
|
||||||
dcCompatible.SelectObject(pOldFont);
|
|
||||||
|
|
||||||
CRect rect;
|
|
||||||
GetClientRect(&rect);
|
|
||||||
dc.BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// <响应 WM_MOUSEMOVE 消息>
|
|
||||||
// 和QQ的截图差不多的效果,只要鼠标挪到该控件区域,该区域就变换位置
|
|
||||||
//
|
|
||||||
void CMyEdit::OnMouseMove(UINT nFlags, CPoint point)
|
|
||||||
{
|
|
||||||
CEdit::OnMouseMove(nFlags, point);
|
|
||||||
CRect rect;
|
|
||||||
GetWindowRect(&rect);
|
|
||||||
int xScreen = GetSystemMetrics(SM_CXSCREEN);
|
|
||||||
if(m_bMove)
|
|
||||||
{
|
|
||||||
//移动到左上角
|
|
||||||
MoveWindow(10,10,rect.Width(),rect.Height());
|
|
||||||
m_bMove=FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//移动到右上角
|
|
||||||
MoveWindow(xScreen-180,10,rect.Width(),rect.Height());
|
|
||||||
m_bMove=TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
void CMyEdit::OnSetFocus(CWnd* pOldWnd)
|
|
||||||
{
|
|
||||||
CEdit::OnSetFocus(pOldWnd);
|
|
||||||
|
|
||||||
// 隐藏光标提示符
|
|
||||||
this->HideCaret();
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyEdit::OnEraseBkgnd(CDC* pDC)
|
|
||||||
{
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/*****************************************************************************
|
|
||||||
* FileName : MyEdit.h
|
|
||||||
* Author : Unknown
|
|
||||||
* Mender : sudami
|
|
||||||
* Time : 2007/09/09
|
|
||||||
*
|
|
||||||
* Comment :
|
|
||||||
*--------------------------------------------------------
|
|
||||||
* 截图程序中的一个控件封装类.
|
|
||||||
* 将控件和该类关联后,可以显示出当前截图的一些提示信息
|
|
||||||
*--------------------------------------------------------
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#if !defined(AFX_MYEDIT_H__A34EEA6D_E8FC_4D15_B03C_BAA42FDF6FCB__INCLUDED_)
|
|
||||||
#define AFX_MYEDIT_H__A34EEA6D_E8FC_4D15_B03C_BAA42FDF6FCB__INCLUDED_
|
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
|
||||||
#pragma once
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#include <afxwin.h>
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class CMyEdit : public CEdit
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMyEdit();
|
|
||||||
virtual ~CMyEdit();
|
|
||||||
|
|
||||||
BOOL m_bMove; // 类似"单刀双掷开关"
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
|
|
||||||
afx_msg void OnSetFocus(CWnd* pOldWnd);
|
|
||||||
|
|
||||||
afx_msg void OnPaint();
|
|
||||||
|
|
||||||
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
|
|
||||||
|
|
||||||
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
|
|
||||||
|
|
||||||
DECLARE_MESSAGE_MAP()
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,148 +0,0 @@
|
|||||||
#include "StdAfx.h"
|
|
||||||
#include "MyToolBar.h"
|
|
||||||
#include <GdiPlus.h>
|
|
||||||
#include "resource.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOL ImageFromIDResource(UINT nID, LPCTSTR sTR, Gdiplus::Bitmap * & pImg)
|
|
||||||
{
|
|
||||||
HINSTANCE hInst = AfxGetResourceHandle();
|
|
||||||
HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
|
|
||||||
if (!hRsrc)
|
|
||||||
return FALSE;
|
|
||||||
// load resource into memory
|
|
||||||
DWORD len = SizeofResource(hInst, hRsrc);
|
|
||||||
BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
|
|
||||||
if (!lpRsrc)
|
|
||||||
return FALSE;
|
|
||||||
// Allocate global memory on which to create stream
|
|
||||||
HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
|
|
||||||
BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
|
|
||||||
memcpy(pmem,lpRsrc,len);
|
|
||||||
IStream* pstm;
|
|
||||||
CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
|
|
||||||
// load from stream
|
|
||||||
pImg=Gdiplus::Bitmap::FromStream(pstm);
|
|
||||||
// free/release stuff
|
|
||||||
GlobalUnlock(m_hMem);
|
|
||||||
pstm->Release();
|
|
||||||
FreeResource(lpRsrc);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMyToolBar::CMyToolBar()
|
|
||||||
{
|
|
||||||
m_hImageList = NULL;
|
|
||||||
m_hWnd_toolbar = 0;
|
|
||||||
m_hWndParent = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMyToolBar::~CMyToolBar(void)
|
|
||||||
{
|
|
||||||
ImageList_Destroy(m_hImageList);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyToolBar::CreateToolBar(HWND hWndParent)
|
|
||||||
{
|
|
||||||
if (m_hImageList)
|
|
||||||
return FALSE;
|
|
||||||
m_hWndParent = hWndParent;
|
|
||||||
|
|
||||||
m_hImageList= ImageList_Create(18,18,ILC_COLOR32,1,1);
|
|
||||||
Gdiplus::Bitmap * pImage = NULL;
|
|
||||||
for(int i=0;i< 9;i++)
|
|
||||||
{
|
|
||||||
ImageFromIDResource(IDB_RECTANGLE + i,_T("PNG"),pImage);
|
|
||||||
HBITMAP pHbitmap=0;;
|
|
||||||
if(pImage)
|
|
||||||
{
|
|
||||||
pImage->GetHBITMAP(Gdiplus::Color(0xff,0xff,0xff,0xff),&pHbitmap);
|
|
||||||
ImageList_Add(m_hImageList,pHbitmap,NULL);
|
|
||||||
delete pImage;
|
|
||||||
pImage = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_hWnd_toolbar = ::CreateWindowEx(0,TOOLBARCLASSNAME,0,WS_CHILD | WS_VISIBLE|WS_BORDER ,
|
|
||||||
0,0,0,0,hWndParent,NULL,GetModuleHandle(NULL),NULL);
|
|
||||||
|
|
||||||
if (m_hWnd_toolbar == NULL)
|
|
||||||
return FALSE;
|
|
||||||
::SendMessage(m_hWnd_toolbar,TB_SETIMAGELIST, 0, (LPARAM) m_hImageList);
|
|
||||||
::SendMessage(m_hWnd_toolbar,TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
|
||||||
|
|
||||||
|
|
||||||
::SendMessage(m_hWnd_toolbar,
|
|
||||||
(UINT) TB_SETBITMAPSIZE,(WPARAM) 0,//not used, must be zero
|
|
||||||
(LPARAM) MAKELONG (18, 18)// = (LPARAM) MAKELONG (dxBitmap, dyBitmap)
|
|
||||||
);
|
|
||||||
|
|
||||||
//TCHAR tooltips[16][30]={_T("AAAA"),_T("BBBB"),_T("CCCC"),_T("DDDD")};
|
|
||||||
for(int i = 0; i < 9; i++)
|
|
||||||
{
|
|
||||||
TBBUTTON tbbutton;
|
|
||||||
// 换行
|
|
||||||
int wrapnow = 0;
|
|
||||||
//if (i % 2 == 1)
|
|
||||||
// wrapnow = TBSTATE_WRAP;
|
|
||||||
|
|
||||||
ZeroMemory(&tbbutton, sizeof(TBBUTTON));
|
|
||||||
//tbbutton.iString = (INT_PTR) tooltips[i];
|
|
||||||
tbbutton.fsStyle = TBSTYLE_CHECKGROUP; // 单选属性
|
|
||||||
tbbutton.fsState = TBSTATE_ENABLED | wrapnow;
|
|
||||||
tbbutton.idCommand = MyToolBar_ID + i; // 定义控件的id
|
|
||||||
tbbutton.iBitmap = i;
|
|
||||||
|
|
||||||
::SendMessage(m_hWnd_toolbar,TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
|
|
||||||
}
|
|
||||||
::SendMessage(m_hWnd_toolbar, TB_AUTOSIZE, 0, 0);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
HWND CMyToolBar::GetHWND()
|
|
||||||
{
|
|
||||||
return m_hWnd_toolbar;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::AddChildStyle()
|
|
||||||
{
|
|
||||||
DWORD dwStyle = GetWindowLong(m_hWnd_toolbar, GWL_STYLE);
|
|
||||||
dwStyle &= WS_CHILD;
|
|
||||||
SetWindowLong(m_hWnd_toolbar,GWL_STYLE,dwStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::RemoveChildStyle()
|
|
||||||
{
|
|
||||||
|
|
||||||
DWORD dwStyle = GetWindowLong(m_hWnd_toolbar, GWL_STYLE);
|
|
||||||
dwStyle &= ~WS_CHILD;
|
|
||||||
SetWindowLong(m_hWnd_toolbar,GWL_STYLE,dwStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::ShowToolBar()
|
|
||||||
{
|
|
||||||
::ShowWindow(m_hWnd_toolbar,SW_SHOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::HideToolBar()
|
|
||||||
{
|
|
||||||
::ShowWindow(m_hWnd_toolbar,SW_HIDE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::SetAtCurMousePlase()
|
|
||||||
{
|
|
||||||
RECT rtWin = {0};
|
|
||||||
::GetWindowRect(m_hWnd_toolbar,&rtWin);
|
|
||||||
POINT pt = {0};
|
|
||||||
::GetCursorPos(&pt);
|
|
||||||
this->SetShowPlace(pt.x,pt.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyToolBar::SetShowPlace(int nCurPointX,int nCurPointY)
|
|
||||||
{
|
|
||||||
|
|
||||||
RECT rtWin = {0};
|
|
||||||
::GetWindowRect(m_hWnd_toolbar,&rtWin);
|
|
||||||
::SetWindowPos(m_hWnd_toolbar,HWND_TOP,nCurPointX - (rtWin.right-rtWin.left),nCurPointY + 2,0,0,SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
|
|
||||||
#define MyToolBar_ID 600
|
|
||||||
|
|
||||||
class CMyToolBar
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CMyToolBar();
|
|
||||||
~CMyToolBar(void);
|
|
||||||
|
|
||||||
BOOL CreateToolBar(HWND hWndParent);
|
|
||||||
void AddChildStyle();
|
|
||||||
void RemoveChildStyle();
|
|
||||||
void ShowToolBar();
|
|
||||||
void HideToolBar();
|
|
||||||
void SetAtCurMousePlase();
|
|
||||||
void SetShowPlace(int nCurPointX,int nCurPointY);
|
|
||||||
HWND GetHWND();
|
|
||||||
private:
|
|
||||||
HIMAGELIST m_hImageList;
|
|
||||||
HWND m_hWndParent;
|
|
||||||
HWND m_hWnd_toolbar;
|
|
||||||
};
|
|
@ -1,839 +0,0 @@
|
|||||||
// This is a part of the Microsoft Foundation Classes C++ library.
|
|
||||||
// Copyright (C) 1992-1998 Microsoft Corporation
|
|
||||||
// All rights reserved.
|
|
||||||
//
|
|
||||||
// This source code is only intended as a supplement to the
|
|
||||||
// Microsoft Foundation Classes Reference and related
|
|
||||||
// electronic documentation provided with the library.
|
|
||||||
// See these sources for detailed information regarding the
|
|
||||||
// Microsoft Foundation Classes product.
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "MyTracker.h"
|
|
||||||
#include "Resource.h"
|
|
||||||
#include "CatchScreenDlg.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMyTracker global state
|
|
||||||
|
|
||||||
// various GDI objects we need to draw
|
|
||||||
AFX_STATIC_DATA HCURSOR _afxCursors[10] = { 0,};
|
|
||||||
AFX_STATIC_DATA HBRUSH _afxHatchBrush = 0;
|
|
||||||
AFX_STATIC_DATA HPEN _afxBlackDottedPen = 0;
|
|
||||||
AFX_STATIC_DATA HPEN _afxBlackSolidPen = 0;
|
|
||||||
AFX_STATIC_DATA int _afxHandleSize = 0;
|
|
||||||
|
|
||||||
void AFX_CDECL AfxTrackerTerm()
|
|
||||||
{
|
|
||||||
AfxDeleteObject((HGDIOBJ*)&_afxHatchBrush);
|
|
||||||
AfxDeleteObject((HGDIOBJ*)&_afxBlackDottedPen);
|
|
||||||
}
|
|
||||||
char _afxTrackerTerm = (char)atexit(&AfxTrackerTerm);
|
|
||||||
|
|
||||||
// the struct below is used to determine the qualities of a particular handle
|
|
||||||
struct AFX_HANDLEINFO
|
|
||||||
{
|
|
||||||
size_t nOffsetX; // offset within RECT for X coordinate
|
|
||||||
size_t nOffsetY; // offset within RECT for Y coordinate
|
|
||||||
int nCenterX; // adjust X by Width()/2 * this number
|
|
||||||
int nCenterY; // adjust Y by Height()/2 * this number
|
|
||||||
int nHandleX; // adjust X by handle size * this number
|
|
||||||
int nHandleY; // adjust Y by handle size * this number
|
|
||||||
int nInvertX; // handle converts to this when X inverted
|
|
||||||
int nInvertY; // handle converts to this when Y inverted
|
|
||||||
};
|
|
||||||
|
|
||||||
// this array describes all 8 handles (clock-wise)
|
|
||||||
AFX_STATIC_DATA const AFX_HANDLEINFO _afxHandleInfo[] =
|
|
||||||
{
|
|
||||||
// corner handles (top-left, top-right, bottom-right, bottom-left
|
|
||||||
{ offsetof(RECT, left), offsetof(RECT, top), 0, 0, 0, 0, 1, 3 },
|
|
||||||
{ offsetof(RECT, right), offsetof(RECT, top), 0, 0, -1, 0, 0, 2 },
|
|
||||||
{ offsetof(RECT, right), offsetof(RECT, bottom), 0, 0, -1, -1, 3, 1 },
|
|
||||||
{ offsetof(RECT, left), offsetof(RECT, bottom), 0, 0, 0, -1, 2, 0 },
|
|
||||||
|
|
||||||
// side handles (top, right, bottom, left)
|
|
||||||
{ offsetof(RECT, left), offsetof(RECT, top), 1, 0, 0, 0, 4, 6 },
|
|
||||||
{ offsetof(RECT, right), offsetof(RECT, top), 0, 1, -1, 0, 7, 5 },
|
|
||||||
{ offsetof(RECT, left), offsetof(RECT, bottom), 1, 0, 0, -1, 6, 4 },
|
|
||||||
{ offsetof(RECT, left), offsetof(RECT, top), 0, 1, 0, 0, 5, 7 }
|
|
||||||
};
|
|
||||||
|
|
||||||
// the struct below gives us information on the layout of a RECT struct and
|
|
||||||
// the relationship between its members
|
|
||||||
struct AFX_RECTINFO
|
|
||||||
{
|
|
||||||
size_t nOffsetAcross; // offset of opposite point (ie. left->right)
|
|
||||||
int nSignAcross; // sign relative to that point (ie. add/subtract)
|
|
||||||
};
|
|
||||||
|
|
||||||
// this array is indexed by the offset of the RECT member / sizeof(int)
|
|
||||||
AFX_STATIC_DATA const AFX_RECTINFO _afxRectInfo[] =
|
|
||||||
{
|
|
||||||
{ offsetof(RECT, right), +1 },
|
|
||||||
{ offsetof(RECT, bottom), +1 },
|
|
||||||
{ offsetof(RECT, left), -1 },
|
|
||||||
{ offsetof(RECT, top), -1 },
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMyTracker intitialization
|
|
||||||
|
|
||||||
CMyTracker::CMyTracker(LPCRECT lpSrcRect, UINT nStyle)
|
|
||||||
{
|
|
||||||
ASSERT(AfxIsValidAddress(lpSrcRect, sizeof(RECT), FALSE));
|
|
||||||
|
|
||||||
Construct();
|
|
||||||
m_rect.CopyRect(lpSrcRect);
|
|
||||||
m_nStyle = nStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMyTracker::CMyTracker()
|
|
||||||
{
|
|
||||||
Construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::Construct()
|
|
||||||
{
|
|
||||||
// do one-time initialization if necessary
|
|
||||||
//********************************************************
|
|
||||||
m_rectColor=RGB(0,0,0);
|
|
||||||
//********************************************************
|
|
||||||
AfxLockGlobals(CRIT_RECTTRACKER);
|
|
||||||
static BOOL bInitialized;
|
|
||||||
if (!bInitialized)
|
|
||||||
{
|
|
||||||
// sanity checks for assumptions we make in the code
|
|
||||||
ASSERT(sizeof(((RECT*)NULL)->left) == sizeof(int));
|
|
||||||
ASSERT(offsetof(RECT, top) > offsetof(RECT, left));
|
|
||||||
ASSERT(offsetof(RECT, right) > offsetof(RECT, top));
|
|
||||||
ASSERT(offsetof(RECT, bottom) > offsetof(RECT, right));
|
|
||||||
|
|
||||||
if (_afxHatchBrush == NULL)
|
|
||||||
{
|
|
||||||
// create the hatch pattern + bitmap
|
|
||||||
WORD hatchPattern[8];
|
|
||||||
WORD wPattern = 0x1111;
|
|
||||||
for (int i = 0; i < 4; i++)
|
|
||||||
{
|
|
||||||
hatchPattern[i] = wPattern;
|
|
||||||
hatchPattern[i+4] = wPattern;
|
|
||||||
wPattern <<= 1;
|
|
||||||
}
|
|
||||||
HBITMAP hatchBitmap = CreateBitmap(8, 8, 1, 1, &hatchPattern);
|
|
||||||
if (hatchBitmap == NULL)
|
|
||||||
{
|
|
||||||
AfxUnlockGlobals(CRIT_RECTTRACKER);
|
|
||||||
AfxThrowResourceException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// create black hatched brush
|
|
||||||
_afxHatchBrush = CreatePatternBrush(hatchBitmap);
|
|
||||||
DeleteObject(hatchBitmap);
|
|
||||||
if (_afxHatchBrush == NULL)
|
|
||||||
{
|
|
||||||
AfxUnlockGlobals(CRIT_RECTTRACKER);
|
|
||||||
AfxThrowResourceException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//CreatePen for DottedLine and SolidLine
|
|
||||||
CreatePen();
|
|
||||||
|
|
||||||
// Note: all track cursors must live in same module
|
|
||||||
HINSTANCE hInst = AfxFindResourceHandle(
|
|
||||||
MAKEINTRESOURCE(AFX_IDC_TRACK4WAY), RT_GROUP_CURSOR);
|
|
||||||
|
|
||||||
// initialize the cursor array
|
|
||||||
_afxCursors[0] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNWSE));
|
|
||||||
_afxCursors[1] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNESW));
|
|
||||||
_afxCursors[2] = _afxCursors[0];
|
|
||||||
_afxCursors[3] = _afxCursors[1];
|
|
||||||
_afxCursors[4] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKNS));
|
|
||||||
_afxCursors[5] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACKWE));
|
|
||||||
_afxCursors[6] = _afxCursors[4];
|
|
||||||
_afxCursors[7] = _afxCursors[5];
|
|
||||||
_afxCursors[8] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_TRACK4WAY));
|
|
||||||
_afxCursors[9] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_MOVE4WAY));
|
|
||||||
|
|
||||||
// get default handle size from Windows profile setting
|
|
||||||
static const TCHAR szWindows[] = _T("windows");
|
|
||||||
static const TCHAR szInplaceBorderWidth[] =
|
|
||||||
_T("oleinplaceborderwidth");
|
|
||||||
_afxHandleSize = GetProfileInt(szWindows, szInplaceBorderWidth, 4);
|
|
||||||
bInitialized = TRUE;
|
|
||||||
}
|
|
||||||
AfxUnlockGlobals(CRIT_RECTTRACKER);
|
|
||||||
|
|
||||||
m_nStyle = 0;
|
|
||||||
m_nHandleSize = _afxHandleSize;
|
|
||||||
m_sizeMin.cy = m_sizeMin.cx = m_nHandleSize*2;
|
|
||||||
|
|
||||||
m_rectLast.SetRectEmpty();
|
|
||||||
m_sizeLast.cx = m_sizeLast.cy = 0;
|
|
||||||
m_bErase = FALSE;
|
|
||||||
m_bFinalErase = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMyTracker::~CMyTracker()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMyTracker operations
|
|
||||||
|
|
||||||
void CMyTracker::Draw(CDC* pDC) const
|
|
||||||
{
|
|
||||||
// set initial DC state
|
|
||||||
VERIFY(pDC->SaveDC() != 0);
|
|
||||||
pDC->SetMapMode(MM_TEXT);
|
|
||||||
pDC->SetViewportOrg(0, 0);
|
|
||||||
pDC->SetWindowOrg(0, 0);
|
|
||||||
|
|
||||||
// get normalized rectangle
|
|
||||||
CRect rect = m_rect;
|
|
||||||
rect.NormalizeRect();
|
|
||||||
|
|
||||||
CPen* pOldPen = NULL;
|
|
||||||
CBrush* pOldBrush = NULL;
|
|
||||||
CGdiObject* pTemp;
|
|
||||||
int nOldROP;
|
|
||||||
|
|
||||||
// draw lines
|
|
||||||
if ((m_nStyle & (dottedLine|solidLine)) != 0)
|
|
||||||
{
|
|
||||||
if (m_nStyle & dottedLine)
|
|
||||||
{
|
|
||||||
//改变当前矩形颜色
|
|
||||||
pOldPen = pDC->SelectObject(CPen::FromHandle(_afxBlackDottedPen));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//改变当前矩形颜色
|
|
||||||
//pOldPen = (CPen*)pDC->SelectStockObject(BLACK_PEN); //BLACK_PEN
|
|
||||||
pOldPen = pDC->SelectObject(CPen::FromHandle(_afxBlackSolidPen));
|
|
||||||
}
|
|
||||||
|
|
||||||
pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
|
|
||||||
nOldROP = pDC->SetROP2(R2_COPYPEN);
|
|
||||||
rect.InflateRect(+1, +1); // borders are one pixel outside
|
|
||||||
pDC->Rectangle(rect.left, rect.top, rect.right, rect.bottom);
|
|
||||||
pDC->SetROP2(nOldROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if hatchBrush is going to be used, need to unrealize it
|
|
||||||
if ((m_nStyle & (hatchInside|hatchedBorder)) != 0)
|
|
||||||
UnrealizeObject(_afxHatchBrush);
|
|
||||||
|
|
||||||
// hatch inside
|
|
||||||
if ((m_nStyle & hatchInside) != 0)
|
|
||||||
{
|
|
||||||
pTemp = pDC->SelectStockObject(NULL_PEN);
|
|
||||||
if (pOldPen == NULL)
|
|
||||||
pOldPen = (CPen*)pTemp;
|
|
||||||
pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
|
|
||||||
if (pOldBrush == NULL)
|
|
||||||
pOldBrush = (CBrush*)pTemp;
|
|
||||||
pDC->SetBkMode(TRANSPARENT);
|
|
||||||
nOldROP = pDC->SetROP2(R2_MASKNOTPEN);
|
|
||||||
pDC->Rectangle(rect.left+1, rect.top+1, rect.right, rect.bottom);
|
|
||||||
pDC->SetROP2(nOldROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw hatched border
|
|
||||||
if ((m_nStyle & hatchedBorder) != 0)
|
|
||||||
{
|
|
||||||
pTemp = pDC->SelectObject(CBrush::FromHandle(_afxHatchBrush));
|
|
||||||
if (pOldBrush == NULL)
|
|
||||||
pOldBrush = (CBrush*)pTemp;
|
|
||||||
pDC->SetBkMode(OPAQUE);
|
|
||||||
CRect rectTrue;
|
|
||||||
GetTrueRect(&rectTrue);
|
|
||||||
pDC->PatBlt(rectTrue.left, rectTrue.top, rectTrue.Width(),
|
|
||||||
rect.top-rectTrue.top, 0x000F0001 /* Pn */);
|
|
||||||
pDC->PatBlt(rectTrue.left, rect.bottom,
|
|
||||||
rectTrue.Width(), rectTrue.bottom-rect.bottom, 0x000F0001 /* Pn */);
|
|
||||||
pDC->PatBlt(rectTrue.left, rect.top, rect.left-rectTrue.left,
|
|
||||||
rect.Height(), 0x000F0001 /* Pn */);
|
|
||||||
pDC->PatBlt(rect.right, rect.top, rectTrue.right-rect.right,
|
|
||||||
rect.Height(), 0x000F0001 /* Pn */);
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw resize handles
|
|
||||||
if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
|
|
||||||
{
|
|
||||||
UINT mask = GetHandleMask();
|
|
||||||
for (int i = 0; i < 8; ++i)
|
|
||||||
{
|
|
||||||
if (mask & (1<<i))
|
|
||||||
{
|
|
||||||
GetHandleRect((TrackerHit)i, &rect);
|
|
||||||
//改变当前调整手柄矩形颜色,也就是那八个点
|
|
||||||
pDC->FillSolidRect(rect, m_rectColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup pDC state
|
|
||||||
if (pOldPen != NULL)
|
|
||||||
pDC->SelectObject(pOldPen);
|
|
||||||
if (pOldBrush != NULL)
|
|
||||||
pDC->SelectObject(pOldBrush);
|
|
||||||
VERIFY(pDC->RestoreDC(-1));
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyTracker::SetCursor(CWnd* pWnd, UINT nHitTest) const
|
|
||||||
{
|
|
||||||
// trackers should only be in client area
|
|
||||||
if (nHitTest != HTCLIENT)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
// convert cursor position to client co-ordinates
|
|
||||||
CPoint point;
|
|
||||||
GetCursorPos(&point);
|
|
||||||
pWnd->ScreenToClient(&point);
|
|
||||||
|
|
||||||
// do hittest and normalize hit
|
|
||||||
int nHandle = HitTestHandles(point);
|
|
||||||
if (nHandle < 0)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
// need to normalize the hittest such that we get proper cursors
|
|
||||||
nHandle = NormalizeHit(nHandle);
|
|
||||||
|
|
||||||
// handle special case of hitting area between handles
|
|
||||||
// (logically the same -- handled as a move -- but different cursor)
|
|
||||||
if (nHandle == hitMiddle && !m_rect.PtInRect(point))
|
|
||||||
{
|
|
||||||
// only for trackers with hatchedBorder (ie. in-place resizing)
|
|
||||||
if (m_nStyle & hatchedBorder)
|
|
||||||
nHandle = (TrackerHit)9;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ASSERT(nHandle < _countof(_afxCursors));
|
|
||||||
::SetCursor(_afxCursors[nHandle]);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMyTracker::HitTest(CPoint point) const
|
|
||||||
{
|
|
||||||
TrackerHit hitResult = hitNothing;
|
|
||||||
|
|
||||||
CRect rectTrue;
|
|
||||||
GetTrueRect(&rectTrue);
|
|
||||||
ASSERT(rectTrue.left <= rectTrue.right);
|
|
||||||
ASSERT(rectTrue.top <= rectTrue.bottom);
|
|
||||||
if (rectTrue.PtInRect(point))
|
|
||||||
{
|
|
||||||
if ((m_nStyle & (resizeInside|resizeOutside)) != 0)
|
|
||||||
hitResult = (TrackerHit)HitTestHandles(point);
|
|
||||||
else
|
|
||||||
hitResult = hitMiddle;
|
|
||||||
}
|
|
||||||
return hitResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMyTracker::NormalizeHit(int nHandle) const
|
|
||||||
{
|
|
||||||
ASSERT(nHandle <= 8 && nHandle >= -1);
|
|
||||||
if (nHandle == hitMiddle || nHandle == hitNothing)
|
|
||||||
return nHandle;
|
|
||||||
const AFX_HANDLEINFO* pHandleInfo = &_afxHandleInfo[nHandle];
|
|
||||||
if (m_rect.Width() < 0)
|
|
||||||
{
|
|
||||||
nHandle = (TrackerHit)pHandleInfo->nInvertX;
|
|
||||||
pHandleInfo = &_afxHandleInfo[nHandle];
|
|
||||||
}
|
|
||||||
if (m_rect.Height() < 0)
|
|
||||||
nHandle = (TrackerHit)pHandleInfo->nInvertY;
|
|
||||||
return nHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyTracker::Track(CWnd* pWnd, CPoint point, BOOL bAllowInvert,
|
|
||||||
CWnd* pWndClipTo)
|
|
||||||
{
|
|
||||||
// perform hit testing on the handles
|
|
||||||
int nHandle = HitTestHandles(point);
|
|
||||||
if (nHandle < 0)
|
|
||||||
{
|
|
||||||
// didn't hit a handle, so just return FALSE
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise, call helper function to do the tracking
|
|
||||||
m_bAllowInvert = bAllowInvert;
|
|
||||||
return TrackHandle(nHandle, pWnd, point, pWndClipTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyTracker::TrackRubberBand(CWnd* pWnd, CPoint point, BOOL bAllowInvert)
|
|
||||||
{
|
|
||||||
// simply call helper function to track from bottom right handle
|
|
||||||
m_bAllowInvert = bAllowInvert;
|
|
||||||
m_rect.SetRect(point.x, point.y, point.x, point.y);
|
|
||||||
return TrackHandle(hitBottomRight, pWnd, point, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::DrawTrackerRect(
|
|
||||||
LPCRECT lpRect, CWnd* pWndClipTo, CDC* pDC, CWnd* pWnd)
|
|
||||||
{
|
|
||||||
// first, normalize the rectangle for drawing
|
|
||||||
|
|
||||||
/*CRect rect = *lpRect;
|
|
||||||
rect.NormalizeRect();
|
|
||||||
|
|
||||||
// convert to client coordinates
|
|
||||||
if (pWndClipTo != NULL)
|
|
||||||
{
|
|
||||||
pWnd->ClientToScreen(&rect);
|
|
||||||
pWndClipTo->ScreenToClient(&rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
CSize size(0, 0);
|
|
||||||
if (!m_bFinalErase)
|
|
||||||
{
|
|
||||||
// otherwise, size depends on the style
|
|
||||||
if (m_nStyle & hatchedBorder)
|
|
||||||
{
|
|
||||||
size.cx = size.cy = max(1, GetHandleSize(rect)-1);
|
|
||||||
rect.InflateRect(size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
size.cx = CX_BORDER;
|
|
||||||
size.cy = CY_BORDER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// and draw it
|
|
||||||
if (m_bFinalErase || !m_bErase)
|
|
||||||
{
|
|
||||||
pDC->DrawDragRect(rect, size, m_rectLast, m_sizeLast);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remember last rectangles
|
|
||||||
m_rectLast = rect;
|
|
||||||
m_sizeLast = size;
|
|
||||||
*/
|
|
||||||
//此函数是画调整大小和位置时画虚线
|
|
||||||
//由于本程序不需要,如果要正常使作的话把上面注示去掉就行了!
|
|
||||||
((CCatchScreenDlg *)pWnd)->InvalidateRgnWindow();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::AdjustRect(int nHandle, LPRECT)
|
|
||||||
{
|
|
||||||
if (nHandle == hitMiddle)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// convert the handle into locations within m_rect
|
|
||||||
int *px, *py;
|
|
||||||
GetModifyPointers(nHandle, &px, &py, NULL, NULL);
|
|
||||||
|
|
||||||
// enforce minimum width
|
|
||||||
int nNewWidth = m_rect.Width();
|
|
||||||
int nAbsWidth = m_bAllowInvert ? abs(nNewWidth) : nNewWidth;
|
|
||||||
if (px != NULL && nAbsWidth < m_sizeMin.cx)
|
|
||||||
{
|
|
||||||
nNewWidth = nAbsWidth != 0 ? nNewWidth / nAbsWidth : 1;
|
|
||||||
//ASSERT((int*)px - (int*)&m_rect < _countof(_afxRectInfo));
|
|
||||||
const AFX_RECTINFO* pRectInfo = &_afxRectInfo[(int*)px - (int*)&m_rect];
|
|
||||||
*px = *(int*)((BYTE*)&m_rect + pRectInfo->nOffsetAcross) +
|
|
||||||
nNewWidth * m_sizeMin.cx * -pRectInfo->nSignAcross;
|
|
||||||
}
|
|
||||||
|
|
||||||
// enforce minimum height
|
|
||||||
int nNewHeight = m_rect.Height();
|
|
||||||
int nAbsHeight = m_bAllowInvert ? abs(nNewHeight) : nNewHeight;
|
|
||||||
if (py != NULL && nAbsHeight < m_sizeMin.cy)
|
|
||||||
{
|
|
||||||
nNewHeight = nAbsHeight != 0 ? nNewHeight / nAbsHeight : 1;
|
|
||||||
//ASSERT((int*)py - (int*)&m_rect < _countof(_afxRectInfo));
|
|
||||||
const AFX_RECTINFO* pRectInfo = &_afxRectInfo[(int*)py - (int*)&m_rect];
|
|
||||||
*py = *(int*)((BYTE*)&m_rect + pRectInfo->nOffsetAcross) +
|
|
||||||
nNewHeight * m_sizeMin.cy * -pRectInfo->nSignAcross;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::GetTrueRect(LPRECT lpTrueRect) const
|
|
||||||
{
|
|
||||||
ASSERT(AfxIsValidAddress(lpTrueRect, sizeof(RECT)));
|
|
||||||
|
|
||||||
CRect rect = m_rect;
|
|
||||||
rect.NormalizeRect();
|
|
||||||
int nInflateBy = 0;
|
|
||||||
if ((m_nStyle & (resizeOutside|hatchedBorder)) != 0)
|
|
||||||
nInflateBy += GetHandleSize() - 1;
|
|
||||||
if ((m_nStyle & (solidLine|dottedLine)) != 0)
|
|
||||||
++nInflateBy;
|
|
||||||
rect.InflateRect(nInflateBy, nInflateBy);
|
|
||||||
*lpTrueRect = rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::OnChangedRect(const CRect& /*rectOld*/)
|
|
||||||
{
|
|
||||||
// no default implementation, useful for derived classes
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMyTracker implementation helpers
|
|
||||||
|
|
||||||
void CMyTracker::GetHandleRect(int nHandle, CRect* pHandleRect) const
|
|
||||||
{
|
|
||||||
ASSERT(nHandle < 8);
|
|
||||||
|
|
||||||
// get normalized rectangle of the tracker
|
|
||||||
CRect rectT = m_rect;
|
|
||||||
rectT.NormalizeRect();
|
|
||||||
if ((m_nStyle & (solidLine|dottedLine)) != 0)
|
|
||||||
rectT.InflateRect(+1, +1);
|
|
||||||
|
|
||||||
// since the rectangle itself was normalized, we also have to invert the
|
|
||||||
// resize handles.
|
|
||||||
nHandle = NormalizeHit(nHandle);
|
|
||||||
|
|
||||||
// handle case of resize handles outside the tracker
|
|
||||||
int size = GetHandleSize();
|
|
||||||
|
|
||||||
if(m_nStyle & resizeOutside)
|
|
||||||
{
|
|
||||||
if(1000000 & m_nStyle)
|
|
||||||
{
|
|
||||||
rectT.InflateRect(size-size/2-1, size-size/2-1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rectT.InflateRect(size-1, size-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate position of the resize handle
|
|
||||||
int nWidth = rectT.Width();
|
|
||||||
int nHeight = rectT.Height();
|
|
||||||
CRect rect;
|
|
||||||
const AFX_HANDLEINFO* pHandleInfo = &_afxHandleInfo[nHandle];
|
|
||||||
rect.left = *(int*)((BYTE*)&rectT + pHandleInfo->nOffsetX);
|
|
||||||
rect.top = *(int*)((BYTE*)&rectT + pHandleInfo->nOffsetY);
|
|
||||||
rect.left += size * pHandleInfo->nHandleX;
|
|
||||||
rect.top += size * pHandleInfo->nHandleY;
|
|
||||||
rect.left += pHandleInfo->nCenterX * (nWidth - size) / 2;
|
|
||||||
rect.top += pHandleInfo->nCenterY * (nHeight - size) / 2;
|
|
||||||
rect.right = rect.left + size;
|
|
||||||
rect.bottom = rect.top + size;
|
|
||||||
|
|
||||||
*pHandleRect = rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMyTracker::GetHandleSize(LPCRECT lpRect) const
|
|
||||||
{
|
|
||||||
if (lpRect == NULL)
|
|
||||||
lpRect = &m_rect;
|
|
||||||
|
|
||||||
int size = m_nHandleSize;
|
|
||||||
if (!(m_nStyle & resizeOutside))
|
|
||||||
{
|
|
||||||
// make sure size is small enough for the size of the rect
|
|
||||||
int sizeMax = min(abs(lpRect->right - lpRect->left),
|
|
||||||
abs(lpRect->bottom - lpRect->top));
|
|
||||||
if (size * 2 > sizeMax)
|
|
||||||
size = sizeMax / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int CMyTracker::HitTestHandles(CPoint point) const
|
|
||||||
{
|
|
||||||
CRect rect;
|
|
||||||
UINT mask = GetHandleMask();
|
|
||||||
|
|
||||||
// see if hit anywhere inside the tracker
|
|
||||||
GetTrueRect(&rect);
|
|
||||||
if (!rect.PtInRect(point))
|
|
||||||
return hitNothing; // totally missed
|
|
||||||
|
|
||||||
// see if we hit a handle
|
|
||||||
for (int i = 0; i < 8; ++i)
|
|
||||||
{
|
|
||||||
if (mask & (1<<i))
|
|
||||||
{
|
|
||||||
GetHandleRect((TrackerHit)i, &rect);
|
|
||||||
if (rect.PtInRect(point))
|
|
||||||
return (TrackerHit)i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// last of all, check for non-hit outside of object, between resize handles
|
|
||||||
if ((m_nStyle & hatchedBorder) == 0)
|
|
||||||
{
|
|
||||||
CRect rect = m_rect;
|
|
||||||
rect.NormalizeRect();
|
|
||||||
if ((m_nStyle & dottedLine|solidLine) != 0)
|
|
||||||
rect.InflateRect(+1, +1);
|
|
||||||
if (!rect.PtInRect(point))
|
|
||||||
return hitNothing; // must have been between resize handles
|
|
||||||
}
|
|
||||||
return hitMiddle; // no handle hit, but hit object (or object border)
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CMyTracker::TrackHandle(int nHandle, CWnd* pWnd, CPoint point,
|
|
||||||
CWnd* pWndClipTo)
|
|
||||||
{
|
|
||||||
ASSERT(nHandle >= 0);
|
|
||||||
ASSERT(nHandle <= 8); // handle 8 is inside the rect
|
|
||||||
|
|
||||||
// don't handle if capture already set
|
|
||||||
if (::GetCapture() != NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
AfxLockTempMaps(); // protect maps while looping
|
|
||||||
|
|
||||||
ASSERT(!m_bFinalErase);
|
|
||||||
|
|
||||||
// save original width & height in pixels
|
|
||||||
int nWidth = m_rect.Width();
|
|
||||||
int nHeight = m_rect.Height();
|
|
||||||
|
|
||||||
// set capture to the window which received this message
|
|
||||||
pWnd->SetCapture();
|
|
||||||
ASSERT(pWnd == CWnd::GetCapture());
|
|
||||||
pWnd->UpdateWindow();
|
|
||||||
if (pWndClipTo != NULL)
|
|
||||||
pWndClipTo->UpdateWindow();
|
|
||||||
CRect rectSave = m_rect;
|
|
||||||
|
|
||||||
// find out what x/y coords we are supposed to modify
|
|
||||||
int *px, *py;
|
|
||||||
int xDiff, yDiff;
|
|
||||||
GetModifyPointers(nHandle, &px, &py, &xDiff, &yDiff);
|
|
||||||
xDiff = point.x - xDiff;
|
|
||||||
yDiff = point.y - yDiff;
|
|
||||||
|
|
||||||
// get DC for drawing
|
|
||||||
CDC* pDrawDC;
|
|
||||||
if (pWndClipTo != NULL)
|
|
||||||
{
|
|
||||||
// clip to arbitrary window by using adjusted Window DC
|
|
||||||
pDrawDC = pWndClipTo->GetDCEx(NULL, DCX_CACHE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// otherwise, just use normal DC
|
|
||||||
pDrawDC = pWnd->GetDC();
|
|
||||||
}
|
|
||||||
ASSERT_VALID(pDrawDC);
|
|
||||||
|
|
||||||
CRect rectOld;
|
|
||||||
BOOL bMoved = FALSE;
|
|
||||||
|
|
||||||
// get messages until capture lost or cancelled/accepted
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
MSG msg;
|
|
||||||
VERIFY(::GetMessage(&msg, NULL, 0, 0));
|
|
||||||
|
|
||||||
if (CWnd::GetCapture() != pWnd)
|
|
||||||
break;
|
|
||||||
|
|
||||||
//增加的,把消息派送给窗口
|
|
||||||
DispatchMessage(&msg);
|
|
||||||
|
|
||||||
switch (msg.message)
|
|
||||||
{
|
|
||||||
// handle movement/accept messages
|
|
||||||
case WM_LBUTTONUP:
|
|
||||||
case WM_MOUSEMOVE:
|
|
||||||
rectOld = m_rect;
|
|
||||||
// handle resize cases (and part of move)
|
|
||||||
if (px != NULL)
|
|
||||||
*px = (int)(short)LOWORD(msg.lParam) - xDiff;
|
|
||||||
if (py != NULL)
|
|
||||||
*py = (int)(short)HIWORD(msg.lParam) - yDiff;
|
|
||||||
|
|
||||||
// handle move case
|
|
||||||
if (nHandle == hitMiddle)
|
|
||||||
{
|
|
||||||
m_rect.right = m_rect.left + nWidth;
|
|
||||||
m_rect.bottom = m_rect.top + nHeight;
|
|
||||||
}
|
|
||||||
// allow caller to adjust the rectangle if necessary
|
|
||||||
AdjustRect(nHandle, &m_rect);
|
|
||||||
|
|
||||||
// only redraw and callback if the rect actually changed!
|
|
||||||
m_bFinalErase = (msg.message == WM_LBUTTONUP);
|
|
||||||
if (!rectOld.EqualRect(&m_rect) || m_bFinalErase)
|
|
||||||
{
|
|
||||||
if (bMoved)
|
|
||||||
{
|
|
||||||
m_bErase = TRUE;
|
|
||||||
DrawTrackerRect(&rectOld, pWndClipTo, pDrawDC, pWnd);
|
|
||||||
}
|
|
||||||
OnChangedRect(rectOld);
|
|
||||||
if (msg.message != WM_LBUTTONUP)
|
|
||||||
{
|
|
||||||
bMoved = TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_bFinalErase)
|
|
||||||
goto ExitLoop;
|
|
||||||
|
|
||||||
if (!rectOld.EqualRect(&m_rect))
|
|
||||||
{
|
|
||||||
m_bErase = FALSE;
|
|
||||||
DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
// handle cancel messages
|
|
||||||
case WM_KEYDOWN:
|
|
||||||
if (msg.wParam != VK_ESCAPE)
|
|
||||||
break;
|
|
||||||
case WM_RBUTTONDOWN:
|
|
||||||
if (bMoved)
|
|
||||||
{
|
|
||||||
m_bErase = m_bFinalErase = TRUE;
|
|
||||||
//DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd);
|
|
||||||
}
|
|
||||||
m_rect = rectSave;
|
|
||||||
goto ExitLoop;
|
|
||||||
|
|
||||||
// just dispatch rest of the messages
|
|
||||||
default:
|
|
||||||
DispatchMessage(&msg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ExitLoop:
|
|
||||||
if (pWndClipTo != NULL)
|
|
||||||
pWndClipTo->ReleaseDC(pDrawDC);
|
|
||||||
else
|
|
||||||
pWnd->ReleaseDC(pDrawDC);
|
|
||||||
ReleaseCapture();
|
|
||||||
|
|
||||||
AfxUnlockTempMaps(FALSE);
|
|
||||||
|
|
||||||
// restore rect in case bMoved is still FALSE
|
|
||||||
if (!bMoved)
|
|
||||||
m_rect = rectSave;
|
|
||||||
m_bFinalErase = FALSE;
|
|
||||||
m_bErase = FALSE;
|
|
||||||
|
|
||||||
// return TRUE only if rect has changed
|
|
||||||
return !rectSave.EqualRect(&m_rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::GetModifyPointers(
|
|
||||||
int nHandle, int** ppx, int** ppy, int* px, int* py)
|
|
||||||
{
|
|
||||||
ASSERT(nHandle >= 0);
|
|
||||||
ASSERT(nHandle <= 8);
|
|
||||||
|
|
||||||
if (nHandle == hitMiddle)
|
|
||||||
nHandle = hitTopLeft; // same as hitting top-left
|
|
||||||
|
|
||||||
*ppx = NULL;
|
|
||||||
*ppy = NULL;
|
|
||||||
|
|
||||||
// fill in the part of the rect that this handle modifies
|
|
||||||
// (Note: handles that map to themselves along a given axis when that
|
|
||||||
// axis is inverted don't modify the value on that axis)
|
|
||||||
|
|
||||||
const AFX_HANDLEINFO* pHandleInfo = &_afxHandleInfo[nHandle];
|
|
||||||
if (pHandleInfo->nInvertX != nHandle)
|
|
||||||
{
|
|
||||||
*ppx = (int*)((BYTE*)&m_rect + pHandleInfo->nOffsetX);
|
|
||||||
if (px != NULL)
|
|
||||||
*px = **ppx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// middle handle on X axis
|
|
||||||
if (px != NULL)
|
|
||||||
*px = m_rect.left + abs(m_rect.Width()) / 2;
|
|
||||||
}
|
|
||||||
if (pHandleInfo->nInvertY != nHandle)
|
|
||||||
{
|
|
||||||
*ppy = (int*)((BYTE*)&m_rect + pHandleInfo->nOffsetY);
|
|
||||||
if (py != NULL)
|
|
||||||
*py = **ppy;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// middle handle on Y axis
|
|
||||||
if (py != NULL)
|
|
||||||
*py = m_rect.top + abs(m_rect.Height()) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT CMyTracker::GetHandleMask() const
|
|
||||||
{
|
|
||||||
UINT mask = 0x0F; // always have 4 corner handles
|
|
||||||
int size = m_nHandleSize*3;
|
|
||||||
if (abs(m_rect.Width()) - size > 4)
|
|
||||||
mask |= 0x50;
|
|
||||||
if (abs(m_rect.Height()) - size > 4)
|
|
||||||
mask |= 0xA0;
|
|
||||||
return mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////增加的函数/////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void CMyTracker::SetRectColor(COLORREF rectColor)
|
|
||||||
{
|
|
||||||
m_rectColor=rectColor;
|
|
||||||
CreatePen();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::CreatePen()
|
|
||||||
{
|
|
||||||
//if (_afxBlackDottedPen == NULL)
|
|
||||||
{
|
|
||||||
// create black dotted pen
|
|
||||||
_afxBlackDottedPen = ::CreatePen(PS_DOT, 0, m_rectColor);
|
|
||||||
if (_afxBlackDottedPen == NULL)
|
|
||||||
{
|
|
||||||
AfxUnlockGlobals(CRIT_RECTTRACKER);
|
|
||||||
AfxThrowResourceException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if (_afxBlackSolidPen == NULL)
|
|
||||||
{
|
|
||||||
// create black dotted pen
|
|
||||||
_afxBlackSolidPen = ::CreatePen(PS_SOLID, 0, m_rectColor);
|
|
||||||
if (_afxBlackSolidPen == NULL)
|
|
||||||
{
|
|
||||||
AfxUnlockGlobals(CRIT_RECTTRACKER);
|
|
||||||
AfxThrowResourceException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMyTracker::SetResizeCursor(UINT nID_N_S,UINT nID_W_E,UINT nID_NW_SE,UINT nID_NE_SW,UINT nIDMiddle)
|
|
||||||
{
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// N
|
|
||||||
// NW -----------|------------NE
|
|
||||||
// | |
|
|
||||||
// | |
|
|
||||||
// W | | E
|
|
||||||
// | Middle |
|
|
||||||
// | |
|
|
||||||
// | |
|
|
||||||
// SW-----------|------------SE
|
|
||||||
// S
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
_afxCursors[0] = AfxGetApp()->LoadCursor(nID_NW_SE); //nw
|
|
||||||
_afxCursors[1] = AfxGetApp()->LoadCursor(nID_NE_SW); //ne
|
|
||||||
_afxCursors[2] = _afxCursors[0]; //se
|
|
||||||
_afxCursors[3] = _afxCursors[1]; //sw
|
|
||||||
_afxCursors[4] = AfxGetApp()->LoadCursor(nID_N_S); //n
|
|
||||||
_afxCursors[5] = AfxGetApp()->LoadCursor(nID_W_E); //w
|
|
||||||
_afxCursors[6] = _afxCursors[4]; //s
|
|
||||||
_afxCursors[7] = _afxCursors[5]; //e
|
|
||||||
_afxCursors[8] = AfxGetApp()->LoadCursor(nIDMiddle); //m
|
|
||||||
// _afxCursors[9] = ::LoadCursor(hInst, MAKEINTRESOURCE(AFX_IDC_MOVE4WAY));
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// CMyTracker - simple rectangular tracking rectangle w/resize handles
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
|
||||||
// Copy from MFC CRectTracker class
|
|
||||||
// Add Some member function
|
|
||||||
// Modify some place
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#define MYTRACKER_
|
|
||||||
|
|
||||||
#define CX_BORDER 1
|
|
||||||
#define CY_BORDER 1
|
|
||||||
|
|
||||||
#define CRIT_RECTTRACKER 5
|
|
||||||
void AFXAPI AfxLockGlobals(int nLockType);
|
|
||||||
void AFXAPI AfxUnlockGlobals(int nLockType);
|
|
||||||
void AFXAPI AfxDeleteObject(HGDIOBJ* pObject);
|
|
||||||
|
|
||||||
class CMyTracker
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Constructors
|
|
||||||
CMyTracker();
|
|
||||||
CMyTracker(LPCRECT lpSrcRect, UINT nStyle);
|
|
||||||
|
|
||||||
// Style Flags
|
|
||||||
enum StyleFlags
|
|
||||||
{
|
|
||||||
solidLine = 1, dottedLine = 2, hatchedBorder = 4,
|
|
||||||
resizeInside = 8, resizeOutside = 16, hatchInside = 32,
|
|
||||||
resizeMiddle =80 //设置中间
|
|
||||||
};
|
|
||||||
|
|
||||||
// Hit-Test codes
|
|
||||||
enum TrackerHit
|
|
||||||
{
|
|
||||||
hitNothing = -1,
|
|
||||||
hitTopLeft = 0, hitTopRight = 1, hitBottomRight = 2, hitBottomLeft = 3,
|
|
||||||
hitTop = 4, hitRight = 5, hitBottom = 6, hitLeft = 7, hitMiddle = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
// Attributes
|
|
||||||
UINT m_nStyle; // current state
|
|
||||||
CRect m_rect; // current position (always in pixels)
|
|
||||||
CSize m_sizeMin; // minimum X and Y size during track operation
|
|
||||||
int m_nHandleSize; // size of resize handles (default from WIN.INI)
|
|
||||||
|
|
||||||
// Operations
|
|
||||||
void Draw(CDC* pDC) const;
|
|
||||||
void GetTrueRect(LPRECT lpTrueRect) const;
|
|
||||||
BOOL SetCursor(CWnd* pWnd, UINT nHitTest) const;
|
|
||||||
BOOL Track(CWnd* pWnd, CPoint point, BOOL bAllowInvert =TRUE,
|
|
||||||
CWnd* pWndClipTo = NULL);
|
|
||||||
BOOL TrackRubberBand(CWnd* pWnd, CPoint point, BOOL bAllowInvert = TRUE);
|
|
||||||
int HitTest(CPoint point) const;
|
|
||||||
int NormalizeHit(int nHandle) const;
|
|
||||||
|
|
||||||
// Overridables
|
|
||||||
virtual void DrawTrackerRect(LPCRECT lpRect, CWnd* pWndClipTo,
|
|
||||||
CDC* pDC, CWnd* pWnd);
|
|
||||||
virtual void AdjustRect(int nHandle, LPRECT lpRect);
|
|
||||||
virtual void OnChangedRect(const CRect& rectOld);
|
|
||||||
virtual UINT GetHandleMask() const;
|
|
||||||
|
|
||||||
// Implementation
|
|
||||||
public:
|
|
||||||
virtual ~CMyTracker();
|
|
||||||
|
|
||||||
public:
|
|
||||||
//***********************************************************
|
|
||||||
//设置调整光标
|
|
||||||
void SetResizeCursor(UINT nID_N_S,UINT nID_W_E,UINT nID_NW_SE,
|
|
||||||
UINT nID_NE_SW,UINT nIDMiddle);
|
|
||||||
//创建军画刷,内部调用
|
|
||||||
void CreatePen();
|
|
||||||
//设置矩形颜色
|
|
||||||
void SetRectColor(COLORREF rectColor);
|
|
||||||
|
|
||||||
//**************************************************************
|
|
||||||
|
|
||||||
//**************************************************************
|
|
||||||
//当前矩形颜色
|
|
||||||
COLORREF m_rectColor;
|
|
||||||
//**************************************************************
|
|
||||||
BOOL m_bAllowInvert; // flag passed to Track or TrackRubberBand
|
|
||||||
CRect m_rectLast;
|
|
||||||
CSize m_sizeLast;
|
|
||||||
BOOL m_bErase; // TRUE if DrawTrackerRect is called for erasing
|
|
||||||
BOOL m_bFinalErase; // TRUE if DragTrackerRect called for final erase
|
|
||||||
|
|
||||||
// implementation helpers
|
|
||||||
int HitTestHandles(CPoint point) const;
|
|
||||||
void GetHandleRect(int nHandle, CRect* pHandleRect) const;
|
|
||||||
void GetModifyPointers(int nHandle, int**ppx, int**ppy, int* px, int*py);
|
|
||||||
virtual int GetHandleSize(LPCRECT lpRect = NULL) const;
|
|
||||||
BOOL TrackHandle(int nHandle, CWnd* pWnd, CPoint point, CWnd* pWndClipTo);
|
|
||||||
void Construct();
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////// END OF FILE /////////////////////////////////////////////////////////
|
|
@ -1,117 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>
|
|
||||||
Dynamic aspect ratio code Copyright (C) 2004 Jacquelin POTIER <jacquelin.potier@free.fr>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; version 2 of the License.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Object: class helper for popupmenu control
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#ifndef _WIN32_WINNT
|
|
||||||
#define _WIN32_WINNT 0x0501 // for xp os
|
|
||||||
#endif
|
|
||||||
#include <windows.h>
|
|
||||||
#pragma warning (push)
|
|
||||||
#pragma warning(disable : 4005)// for '_stprintf' : macro redefinition in tchar.h
|
|
||||||
#include <TCHAR.h>
|
|
||||||
#pragma warning (pop)
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <commctrl.h>
|
|
||||||
#pragma comment (lib,"comctl32.lib")
|
|
||||||
|
|
||||||
class CPopUpMenu
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef void (*pfMessageCallback)(WPARAM wParam, LPARAM lParam,PVOID UserParam);
|
|
||||||
CPopUpMenu();
|
|
||||||
CPopUpMenu(CPopUpMenu* ParentPopUpMenu);
|
|
||||||
~CPopUpMenu();
|
|
||||||
|
|
||||||
HMENU GetControlHandle();
|
|
||||||
CPopUpMenu* GetParentPopUpMenu();
|
|
||||||
|
|
||||||
UINT Add(TCHAR* Name);
|
|
||||||
UINT Add(TCHAR* Name,UINT Index);
|
|
||||||
UINT Add(TCHAR* Name,HICON hIcon);
|
|
||||||
UINT Add(TCHAR* Name,HICON hIcon,UINT Index);
|
|
||||||
UINT Add(TCHAR* Name,int IdIcon,HINSTANCE hInstance);
|
|
||||||
UINT Add(TCHAR* Name,int IdIcon,HINSTANCE hInstance,UINT Index);
|
|
||||||
UINT Add(TCHAR* Name,int IdIcon,HINSTANCE hInstance,int Width,int Height,UINT Index);
|
|
||||||
|
|
||||||
UINT AddSeparator();
|
|
||||||
UINT AddSeparator(UINT Index);
|
|
||||||
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu,UINT Index);
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu);
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu,int IdIcon,HINSTANCE hInstance,UINT Index);
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu,int IdIcon,HINSTANCE hInstance);
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu,HICON hIcon,UINT Index);
|
|
||||||
UINT AddSubMenu(TCHAR* SubMenuName,CPopUpMenu* SubMenu,HICON hIcon);
|
|
||||||
|
|
||||||
void SetCheckedState(UINT MenuID,BOOL bChecked);
|
|
||||||
BOOL IsChecked(UINT MenuID);
|
|
||||||
void SetEnabledState(UINT MenuID,BOOL bEnabled);
|
|
||||||
BOOL IsEnabled(UINT MenuID);
|
|
||||||
BOOL SetText(UINT MenuID,TCHAR* pszText);
|
|
||||||
BOOL SetIcon(UINT MenuID,int IdIcon,HINSTANCE hInstance);
|
|
||||||
BOOL SetIcon(UINT MenuID,int IdIcon,HINSTANCE hInstance,int Width,int Height);
|
|
||||||
BOOL SetIcon(UINT MenuID,HICON hIcon);
|
|
||||||
int GetText(UINT MenuID,TCHAR* pszText,int pszTextMaxSize);
|
|
||||||
CPopUpMenu* GetSubMenu(UINT MenuID);
|
|
||||||
|
|
||||||
void Remove(UINT MenuID);
|
|
||||||
|
|
||||||
int GetItemCount();
|
|
||||||
int GetID(UINT MenuIndex);
|
|
||||||
int GetIndex(UINT MenuId);
|
|
||||||
|
|
||||||
UINT Show(int x,int y, HWND hOwner);
|
|
||||||
UINT Show(int x,int y, HWND hOwner,BOOL PositionRelativeToOwner);
|
|
||||||
UINT Show(int x,int y, HWND hOwner,BOOL PositionRelativeToOwner,BOOL ShowUpper);
|
|
||||||
|
|
||||||
UINT GetNextMenuId();
|
|
||||||
UINT GetMaxMenuId();
|
|
||||||
BOOL ReplaceMenuId(UINT OldMenuID,UINT NewMenuID);
|
|
||||||
|
|
||||||
BOOL SetMouseRightButtonUpCallback(pfMessageCallback Callback,PVOID UserParam);
|
|
||||||
BOOL SetMenuSelectCallback(pfMessageCallback Callback,PVOID UserParam);
|
|
||||||
|
|
||||||
BOOL bAllowIconsEffects;
|
|
||||||
private:
|
|
||||||
CPopUpMenu* ParentPopUpMenu;
|
|
||||||
HMENU hPopUpMenu;
|
|
||||||
int CurrentMenuId;
|
|
||||||
BOOL bThemingEnabledForVistaOrNewer;
|
|
||||||
std::vector<HBITMAP> ListLoadedBitmapToFree;
|
|
||||||
|
|
||||||
pfMessageCallback MouseRightButtonUpCallback;
|
|
||||||
PVOID MouseRightButtonUpUserParam;
|
|
||||||
pfMessageCallback MenuSelectCallback;
|
|
||||||
PVOID MenuSelectUserParam;
|
|
||||||
|
|
||||||
void CommonConstructor();
|
|
||||||
void SetMenuItemBitmapInfo(MENUITEMINFO* pMenuItem,HICON hIcon);
|
|
||||||
BOOL IsSubMenu(HMENU hMenu,HMENU hSubMenu);
|
|
||||||
BOOL OnMeasureItem(HWND hwnd, LPMEASUREITEMSTRUCT lpmis);
|
|
||||||
BOOL OnDrawItem(HWND hwnd, LPDRAWITEMSTRUCT lpdis);
|
|
||||||
void OnMouseRightButtonUp(WPARAM wParam, LPARAM lParam);
|
|
||||||
void OnMenuSelect(WPARAM wParam, LPARAM lParam);
|
|
||||||
void FreeItemMemory(UINT MenuID);
|
|
||||||
void FreeItemBitmap(UINT MenuID);
|
|
||||||
static LRESULT CALLBACK SubClassWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,UINT_PTR uIdSubclass,DWORD_PTR dwRefData);
|
|
||||||
};
|
|
@ -1,174 +0,0 @@
|
|||||||
// Screenshot.cpp : 定义应用程序的类行为。
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "Screenshot.h"
|
|
||||||
#include "ScreenshotDlg.h"
|
|
||||||
#include "CatchScreenDlg.h"
|
|
||||||
#include <GdiPlus.h>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Gdiplus;
|
|
||||||
#pragma comment(lib,"GdiPlus.lib")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
#define new DEBUG_NEW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define SHIFTED 0x8000
|
|
||||||
|
|
||||||
|
|
||||||
// CScreenshotApp
|
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CScreenshotApp, CWinApp)
|
|
||||||
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
|
|
||||||
END_MESSAGE_MAP()
|
|
||||||
|
|
||||||
|
|
||||||
// CScreenshotApp 构造
|
|
||||||
|
|
||||||
CScreenshotApp::CScreenshotApp()
|
|
||||||
{
|
|
||||||
// TODO: 在此处添加构造代码,
|
|
||||||
// 将所有重要的初始化放置在 InitInstance 中
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 唯一的一个 CScreenshotApp 对象
|
|
||||||
|
|
||||||
CScreenshotApp theApp;
|
|
||||||
|
|
||||||
|
|
||||||
// CScreenshotApp 初始化
|
|
||||||
|
|
||||||
BOOL CScreenshotApp::InitInstance()
|
|
||||||
{
|
|
||||||
// 如果一个运行在 Windows XP 上的应用程序清单指定要
|
|
||||||
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
|
|
||||||
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
|
|
||||||
INITCOMMONCONTROLSEX InitCtrls;
|
|
||||||
InitCtrls.dwSize = sizeof(InitCtrls);
|
|
||||||
// 将它设置为包括所有要在应用程序中使用的
|
|
||||||
// 公共控件类。
|
|
||||||
InitCtrls.dwICC = ICC_WIN95_CLASSES;
|
|
||||||
InitCommonControlsEx(&InitCtrls);
|
|
||||||
|
|
||||||
CWinApp::InitInstance();
|
|
||||||
|
|
||||||
GdiplusStartupInput input;
|
|
||||||
GdiplusStartup(&m_gdiplusToken,&input,NULL);
|
|
||||||
|
|
||||||
AfxEnableControlContainer();
|
|
||||||
|
|
||||||
// 标准初始化
|
|
||||||
// 如果未使用这些功能并希望减小
|
|
||||||
// 最终可执行文件的大小,则应移除下列
|
|
||||||
// 不需要的特定初始化例程
|
|
||||||
// 更改用于存储设置的注册表项
|
|
||||||
// TODO: 应适当修改该字符串,
|
|
||||||
// 例如修改为公司或组织名
|
|
||||||
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
|
|
||||||
|
|
||||||
CScreenshotDlg dlg;
|
|
||||||
m_pMainWnd = &dlg;
|
|
||||||
INT_PTR nResponse = dlg.DoModal();
|
|
||||||
if (nResponse == IDOK)
|
|
||||||
{
|
|
||||||
// TODO: 在此放置处理何时用
|
|
||||||
// “确定”来关闭对话框的代码
|
|
||||||
}
|
|
||||||
else if (nResponse == IDCANCEL)
|
|
||||||
{
|
|
||||||
// TODO: 在此放置处理何时用
|
|
||||||
// “取消”来关闭对话框的代码
|
|
||||||
}
|
|
||||||
|
|
||||||
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
|
|
||||||
// 而不是启动应用程序的消息泵。
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL CScreenshotApp::ProcessMessageFilter(int code, LPMSG lpMsg)
|
|
||||||
{
|
|
||||||
if(m_hwndDlg != NULL)
|
|
||||||
{
|
|
||||||
// 如果消息是从对话框发出的或者其子控件发出的,就进行处理
|
|
||||||
if((lpMsg->hwnd == m_hwndDlg) || ::IsChild(m_hwndDlg, lpMsg->hwnd))
|
|
||||||
{
|
|
||||||
// 如果消息是WM_KEYDOWN,用方向键调整位置
|
|
||||||
if(lpMsg->message == WM_KEYDOWN)
|
|
||||||
{
|
|
||||||
CRect rect(0,0,0,0);
|
|
||||||
CCatchScreenDlg * pDlg=(CCatchScreenDlg *)AfxGetMainWnd();
|
|
||||||
|
|
||||||
rect = pDlg->m_rectTracker.m_rect;
|
|
||||||
|
|
||||||
if(pDlg->m_bFirstDraw)
|
|
||||||
{
|
|
||||||
//如果Shift键按下则方向键调整大小
|
|
||||||
BOOL bIsShiftDown = FALSE;
|
|
||||||
|
|
||||||
if (GetKeyState(VK_SHIFT) & SHIFTED)
|
|
||||||
bIsShiftDown = TRUE;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
switch(lpMsg->wParam)
|
|
||||||
{
|
|
||||||
case VK_UP:
|
|
||||||
|
|
||||||
//如果按下Shift,则只调整一边
|
|
||||||
if(!bIsShiftDown)
|
|
||||||
rect.top-=1;
|
|
||||||
|
|
||||||
rect.bottom-=1;
|
|
||||||
pDlg->m_rectTracker.m_rect = rect;
|
|
||||||
pDlg->InvalidateRgnWindow();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_DOWN:
|
|
||||||
rect.top+=1;
|
|
||||||
if(!bIsShiftDown)
|
|
||||||
rect.bottom+=1;
|
|
||||||
|
|
||||||
pDlg->m_rectTracker.m_rect=rect;
|
|
||||||
pDlg->InvalidateRgnWindow();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_LEFT:
|
|
||||||
if(!bIsShiftDown)
|
|
||||||
rect.left-=1;
|
|
||||||
rect.right-=1;
|
|
||||||
|
|
||||||
pDlg->m_rectTracker.m_rect=rect;
|
|
||||||
pDlg->InvalidateRgnWindow();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_RIGHT:
|
|
||||||
rect.left+=1;
|
|
||||||
if(!bIsShiftDown)
|
|
||||||
rect.right+=1;
|
|
||||||
|
|
||||||
pDlg->m_rectTracker.m_rect=rect;
|
|
||||||
pDlg->InvalidateRgnWindow();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return CWinApp::ProcessMessageFilter(code, lpMsg);
|
|
||||||
}
|
|
||||||
int CScreenshotApp::ExitInstance()
|
|
||||||
{
|
|
||||||
GdiplusShutdown(m_gdiplusToken);
|
|
||||||
|
|
||||||
return CWinApp::ExitInstance();
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
// Screenshot.h : PROJECT_NAME 应用程序的主头文件
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef __AFXWIN_H__
|
|
||||||
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "resource.h" // 主符号
|
|
||||||
|
|
||||||
// CScreenshotApp:
|
|
||||||
// 有关此类的实现,请参阅 Screenshot.cpp
|
|
||||||
//
|
|
||||||
|
|
||||||
class CScreenshotApp : public CWinApp
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CScreenshotApp();
|
|
||||||
|
|
||||||
// 重写
|
|
||||||
public:
|
|
||||||
virtual BOOL InitInstance();
|
|
||||||
|
|
||||||
|
|
||||||
HWND m_hwndDlg;
|
|
||||||
virtual BOOL ProcessMessageFilter(int code, LPMSG lpMsg);
|
|
||||||
|
|
||||||
// 实现
|
|
||||||
|
|
||||||
DECLARE_MESSAGE_MAP()
|
|
||||||
private:
|
|
||||||
ULONG_PTR m_gdiplusToken;
|
|
||||||
public:
|
|
||||||
virtual int ExitInstance();
|
|
||||||
};
|
|
||||||
|
|
||||||
extern CScreenshotApp theApp;
|
|
@ -1,217 +0,0 @@
|
|||||||
// Microsoft Visual C++ generated resource script.
|
|
||||||
//
|
|
||||||
#include "resource.h"
|
|
||||||
|
|
||||||
#define APSTUDIO_READONLY_SYMBOLS
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Generated from the TEXTINCLUDE 2 resource.
|
|
||||||
//
|
|
||||||
#ifndef APSTUDIO_INVOKED
|
|
||||||
#include "targetver.h"
|
|
||||||
#endif
|
|
||||||
#include "afxres.h"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
#undef APSTUDIO_READONLY_SYMBOLS
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Chinese (P.R.C.) resources
|
|
||||||
|
|
||||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
|
|
||||||
#ifdef _WIN32
|
|
||||||
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
|
|
||||||
#pragma code_page(936)
|
|
||||||
#endif //_WIN32
|
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// TEXTINCLUDE
|
|
||||||
//
|
|
||||||
|
|
||||||
1 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"resource.h\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
2 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"#ifndef APSTUDIO_INVOKED\r\n"
|
|
||||||
"#include ""targetver.h""\r\n"
|
|
||||||
"#endif\r\n"
|
|
||||||
"#include ""afxres.h""\r\n"
|
|
||||||
"\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
3 TEXTINCLUDE
|
|
||||||
BEGIN
|
|
||||||
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
|
|
||||||
"#define _AFX_NO_OLE_RESOURCES\r\n"
|
|
||||||
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
|
|
||||||
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
|
|
||||||
"\r\n"
|
|
||||||
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)\r\n"
|
|
||||||
"LANGUAGE 4, 2\r\n"
|
|
||||||
"#pragma code_page(936)\r\n"
|
|
||||||
"#include ""res\\Screenshot.rc2"" // 非 Microsoft Visual C++ 编辑的资源\r\n"
|
|
||||||
"#include ""l.CHS\\afxres.rc"" // 标准组件\r\n"
|
|
||||||
"#endif\r\n"
|
|
||||||
"\0"
|
|
||||||
END
|
|
||||||
|
|
||||||
#endif // APSTUDIO_INVOKED
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Icon
|
|
||||||
//
|
|
||||||
|
|
||||||
// Icon with lowest ID value placed first to ensure application icon
|
|
||||||
// remains consistent on all systems.
|
|
||||||
IDR_MAINFRAME ICON "res\\Screenshot.ico"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Dialog
|
|
||||||
//
|
|
||||||
|
|
||||||
IDD_SCREENSHOT_DIALOG DIALOGEX 0, 0, 181, 59
|
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
|
|
||||||
EXSTYLE WS_EX_APPWINDOW
|
|
||||||
CAPTION "Screenshot"
|
|
||||||
FONT 9, "MS Shell Dlg", 0, 0, 0x1
|
|
||||||
BEGIN
|
|
||||||
PUSHBUTTON "截图",IDC_BTN_START,65,22,50,14
|
|
||||||
END
|
|
||||||
|
|
||||||
IDD_DIALOGFORIMG DIALOGEX 0, 0, 169, 140
|
|
||||||
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP
|
|
||||||
EXSTYLE WS_EX_TRANSPARENT
|
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
|
||||||
BEGIN
|
|
||||||
EDITTEXT IDC_EDIT1,14,20,137,93,ES_MULTILINE | ES_READONLY | NOT WS_BORDER
|
|
||||||
END
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Version
|
|
||||||
//
|
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
|
||||||
FILEVERSION 1,0,0,1
|
|
||||||
PRODUCTVERSION 1,0,0,1
|
|
||||||
FILEFLAGSMASK 0x3fL
|
|
||||||
#ifdef _DEBUG
|
|
||||||
FILEFLAGS 0x1L
|
|
||||||
#else
|
|
||||||
FILEFLAGS 0x0L
|
|
||||||
#endif
|
|
||||||
FILEOS 0x4L
|
|
||||||
FILETYPE 0x1L
|
|
||||||
FILESUBTYPE 0x0L
|
|
||||||
BEGIN
|
|
||||||
BLOCK "StringFileInfo"
|
|
||||||
BEGIN
|
|
||||||
BLOCK "080403a8"
|
|
||||||
BEGIN
|
|
||||||
VALUE "CompanyName", "TODO: <公司名>"
|
|
||||||
VALUE "FileDescription", "TODO: <文件说明>"
|
|
||||||
VALUE "FileVersion", "1.0.0.1"
|
|
||||||
VALUE "InternalName", "Screenshot.exe"
|
|
||||||
VALUE "LegalCopyright", "TODO: (C) <公司名>。保留所有权利。"
|
|
||||||
VALUE "OriginalFilename", "Screenshot.exe"
|
|
||||||
VALUE "ProductName", "TODO: <产品名>"
|
|
||||||
VALUE "ProductVersion", "1.0.0.1"
|
|
||||||
END
|
|
||||||
END
|
|
||||||
BLOCK "VarFileInfo"
|
|
||||||
BEGIN
|
|
||||||
VALUE "Translation", 0x804, 936
|
|
||||||
END
|
|
||||||
END
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// DESIGNINFO
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
GUIDELINES DESIGNINFO
|
|
||||||
BEGIN
|
|
||||||
IDD_SCREENSHOT_DIALOG, DIALOG
|
|
||||||
BEGIN
|
|
||||||
LEFTMARGIN, 7
|
|
||||||
RIGHTMARGIN, 174
|
|
||||||
TOPMARGIN, 7
|
|
||||||
BOTTOMMARGIN, 52
|
|
||||||
END
|
|
||||||
|
|
||||||
IDD_DIALOGFORIMG, DIALOG
|
|
||||||
BEGIN
|
|
||||||
LEFTMARGIN, 7
|
|
||||||
RIGHTMARGIN, 162
|
|
||||||
TOPMARGIN, 7
|
|
||||||
BOTTOMMARGIN, 133
|
|
||||||
END
|
|
||||||
END
|
|
||||||
#endif // APSTUDIO_INVOKED
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Bitmap
|
|
||||||
//
|
|
||||||
|
|
||||||
IDB_BITMAP_BK BITMAP "res\\brackground.bmp"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// PNG
|
|
||||||
//
|
|
||||||
|
|
||||||
IDB_ARROW PNG "res\\Arrow.png"
|
|
||||||
IDB_RECTANGLE PNG "res\\Rectangle.png"
|
|
||||||
IDB_CIRCLE PNG "res\\Circle.png"
|
|
||||||
IDB_BRUSH PNG "res\\Brush.PNG"
|
|
||||||
IDB_MOSAIC PNG "res\\Mosaic.png"
|
|
||||||
IDB_TEXT PNG "res\\Text.png"
|
|
||||||
IDB_UNDO PNG "res\\Undo.png"
|
|
||||||
IDB_SAVE PNG "res\\Save.png"
|
|
||||||
IDB_EXIT PNG "res\\Exit.png"
|
|
||||||
IDB_FINISH PNG "res\\Finish.png"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Cursor
|
|
||||||
//
|
|
||||||
|
|
||||||
IDC_CURSOR1 CURSOR "res\\arrow_m.cur"
|
|
||||||
#endif // Chinese (P.R.C.) resources
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef APSTUDIO_INVOKED
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// Generated from the TEXTINCLUDE 3 resource.
|
|
||||||
//
|
|
||||||
#define _AFX_NO_SPLITTER_RESOURCES
|
|
||||||
#define _AFX_NO_OLE_RESOURCES
|
|
||||||
#define _AFX_NO_TRACKER_RESOURCES
|
|
||||||
#define _AFX_NO_PROPERTY_RESOURCES
|
|
||||||
|
|
||||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
|
|
||||||
LANGUAGE 4, 2
|
|
||||||
#pragma code_page(936)
|
|
||||||
#include "res\Screenshot.rc2" // 非 Microsoft Visual C++ 编辑的资源
|
|
||||||
#include "l.CHS\afxres.rc" // 标准组件
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
#endif // not APSTUDIO_INVOKED
|
|
||||||
|
|
@ -1,368 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="gb2312"?>
|
|
||||||
<VisualStudioProject
|
|
||||||
ProjectType="Visual C++"
|
|
||||||
Version="9.00"
|
|
||||||
Name="Screenshot"
|
|
||||||
ProjectGUID="{24E39ACB-AB81-485D-8D36-749B3F5EC1E8}"
|
|
||||||
RootNamespace="Screenshot"
|
|
||||||
Keyword="MFCProj"
|
|
||||||
TargetFrameworkVersion="196613"
|
|
||||||
>
|
|
||||||
<Platforms>
|
|
||||||
<Platform
|
|
||||||
Name="Win32"
|
|
||||||
/>
|
|
||||||
</Platforms>
|
|
||||||
<ToolFiles>
|
|
||||||
</ToolFiles>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
|
||||||
IntermediateDirectory="$(ConfigurationName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
UseOfMFC="2"
|
|
||||||
CharacterSet="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
PreprocessorDefinitions="_DEBUG"
|
|
||||||
MkTypLibCompatible="false"
|
|
||||||
ValidateParameters="true"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="0"
|
|
||||||
PreprocessorDefinitions="WIN32;_WINDOWS;_DEBUG"
|
|
||||||
MinimalRebuild="true"
|
|
||||||
BasicRuntimeChecks="3"
|
|
||||||
RuntimeLibrary="3"
|
|
||||||
UsePrecompiledHeader="2"
|
|
||||||
WarningLevel="3"
|
|
||||||
DebugInformationFormat="4"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
PreprocessorDefinitions="_DEBUG"
|
|
||||||
Culture="2052"
|
|
||||||
AdditionalIncludeDirectories="$(IntDir)"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
LinkIncremental="1"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="2"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
<Configuration
|
|
||||||
Name="Release|Win32"
|
|
||||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
|
||||||
IntermediateDirectory="$(ConfigurationName)"
|
|
||||||
ConfigurationType="1"
|
|
||||||
UseOfMFC="2"
|
|
||||||
CharacterSet="1"
|
|
||||||
WholeProgramOptimization="1"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreBuildEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCustomBuildTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXMLDataGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCWebServiceProxyGeneratorTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCMIDLTool"
|
|
||||||
PreprocessorDefinitions="NDEBUG"
|
|
||||||
MkTypLibCompatible="false"
|
|
||||||
ValidateParameters="true"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
Optimization="2"
|
|
||||||
EnableIntrinsicFunctions="true"
|
|
||||||
PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG"
|
|
||||||
MinimalRebuild="false"
|
|
||||||
RuntimeLibrary="2"
|
|
||||||
EnableFunctionLevelLinking="true"
|
|
||||||
UsePrecompiledHeader="2"
|
|
||||||
WarningLevel="3"
|
|
||||||
DebugInformationFormat="3"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManagedResourceCompilerTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCResourceCompilerTool"
|
|
||||||
PreprocessorDefinitions="NDEBUG"
|
|
||||||
Culture="2052"
|
|
||||||
AdditionalIncludeDirectories="$(IntDir)"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPreLinkEventTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCLinkerTool"
|
|
||||||
LinkIncremental="1"
|
|
||||||
GenerateDebugInformation="true"
|
|
||||||
SubSystem="2"
|
|
||||||
OptimizeReferences="2"
|
|
||||||
EnableCOMDATFolding="2"
|
|
||||||
TargetMachine="1"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCALinkTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCManifestTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCXDCMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCBscMakeTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCFxCopTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCAppVerifierTool"
|
|
||||||
/>
|
|
||||||
<Tool
|
|
||||||
Name="VCPostBuildEventTool"
|
|
||||||
/>
|
|
||||||
</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<References>
|
|
||||||
</References>
|
|
||||||
<Files>
|
|
||||||
<Filter
|
|
||||||
Name="Source Files"
|
|
||||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
|
||||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\CatchScreenDlg.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyEdit.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyToolBar.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyTracker.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PopUpMenu.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Screenshot.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\ScreenshotDlg.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\stdafx.cpp"
|
|
||||||
>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
UsePrecompiledHeader="1"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32"
|
|
||||||
>
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
UsePrecompiledHeader="1"
|
|
||||||
/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Header Files"
|
|
||||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
|
||||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\CatchScreenDlg.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyEdit.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyToolBar.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\MyTracker.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\PopUpMenu.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Resource.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Screenshot.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\ScreenshotDlg.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\stdafx.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\targetver.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<Filter
|
|
||||||
Name="Resource Files"
|
|
||||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
|
||||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
|
||||||
>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Arrow.ico"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Arrow.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\arrow_m.cur"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\brackground.bmp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Brush.PNG"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Circle.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Exit.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Finish.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Mosaic.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Rectangle.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Save.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Screenshot.ico"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\Screenshot.rc"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Screenshot.rc2"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Text.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\toolbar1.bmp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\res\Undo.png"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Filter>
|
|
||||||
<File
|
|
||||||
RelativePath=".\ReadMe.txt"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
</Files>
|
|
||||||
<Globals>
|
|
||||||
<Global
|
|
||||||
Name="RESOURCE_FILE"
|
|
||||||
Value="Screenshot.rc"
|
|
||||||
/>
|
|
||||||
</Globals>
|
|
||||||
</VisualStudioProject>
|
|
@ -1,116 +0,0 @@
|
|||||||
// ScreenshotDlg.cpp : 实现文件
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "Screenshot.h"
|
|
||||||
#include "ScreenshotDlg.h"
|
|
||||||
|
|
||||||
#include "CatchScreenDlg.h"
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
//#define new DEBUG_NEW
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
// CScreenshotDlg 对话框
|
|
||||||
|
|
||||||
|
|
||||||
CScreenshotDlg::CScreenshotDlg(CWnd* pParent /*=NULL*/)
|
|
||||||
: CDialog(CScreenshotDlg::IDD, pParent)
|
|
||||||
{
|
|
||||||
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScreenshotDlg::DoDataExchange(CDataExchange* pDX)
|
|
||||||
{
|
|
||||||
CDialog::DoDataExchange(pDX);
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN_MESSAGE_MAP(CScreenshotDlg, CDialog)
|
|
||||||
ON_WM_PAINT()
|
|
||||||
ON_WM_QUERYDRAGICON()
|
|
||||||
//}}AFX_MSG_MAP
|
|
||||||
ON_BN_CLICKED(IDC_BTN_START, &CScreenshotDlg::OnBnClickedBtnStart)
|
|
||||||
ON_WM_CTLCOLOR()
|
|
||||||
ON_WM_MOUSEMOVE()
|
|
||||||
END_MESSAGE_MAP()
|
|
||||||
|
|
||||||
|
|
||||||
// CScreenshotDlg 消息处理程序
|
|
||||||
|
|
||||||
BOOL CScreenshotDlg::OnInitDialog()
|
|
||||||
{
|
|
||||||
CDialog::OnInitDialog();
|
|
||||||
|
|
||||||
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
|
|
||||||
// 执行此操作
|
|
||||||
SetIcon(m_hIcon, TRUE); // 设置大图标
|
|
||||||
SetIcon(m_hIcon, FALSE); // 设置小图标
|
|
||||||
|
|
||||||
// TODO: 在此添加额外的初始化代码
|
|
||||||
|
|
||||||
// 使窗体在最顶层
|
|
||||||
::SetWindowPos(GetSafeHwnd(), HWND_TOPMOST, 150, 150, 0, 0,
|
|
||||||
SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW);
|
|
||||||
|
|
||||||
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果向对话框添加最小化按钮,则需要下面的代码
|
|
||||||
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
|
|
||||||
// 这将由框架自动完成。
|
|
||||||
|
|
||||||
void CScreenshotDlg::OnPaint()
|
|
||||||
{
|
|
||||||
if (IsIconic())
|
|
||||||
{
|
|
||||||
CPaintDC dc(this); // 用于绘制的设备上下文
|
|
||||||
|
|
||||||
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
|
|
||||||
|
|
||||||
// 使图标在工作区矩形中居中
|
|
||||||
int cxIcon = GetSystemMetrics(SM_CXICON);
|
|
||||||
int cyIcon = GetSystemMetrics(SM_CYICON);
|
|
||||||
CRect rect;
|
|
||||||
GetClientRect(&rect);
|
|
||||||
int x = (rect.Width() - cxIcon + 1) / 2;
|
|
||||||
int y = (rect.Height() - cyIcon + 1) / 2;
|
|
||||||
|
|
||||||
// 绘制图标
|
|
||||||
dc.DrawIcon(x, y, m_hIcon);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CDialog::OnPaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//当用户拖动最小化窗口时系统调用此函数取得光标
|
|
||||||
//显示。
|
|
||||||
HCURSOR CScreenshotDlg::OnQueryDragIcon()
|
|
||||||
{
|
|
||||||
return static_cast<HCURSOR>(m_hIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
|
||||||
// 线程函数,用来截图
|
|
||||||
//
|
|
||||||
UINT SccreenShot_Thread (LPVOID lpParam)
|
|
||||||
{
|
|
||||||
HWND hWndMain = (HWND) lpParam;
|
|
||||||
CCatchScreenDlg dlg;
|
|
||||||
dlg.DoModal();
|
|
||||||
|
|
||||||
::ShowWindow(hWndMain,SW_SHOW);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CScreenshotDlg::OnBnClickedBtnStart()
|
|
||||||
{
|
|
||||||
::ShowWindow (m_hWnd, SW_HIDE);
|
|
||||||
//使得被激活窗口出现在前景
|
|
||||||
::AfxBeginThread (SccreenShot_Thread, (LPVOID)GetSafeHwnd());
|
|
||||||
//::ShowWindow (GetSafeHwnd(), SW_SHOW);
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
// ScreenshotDlg.h : 头文件
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// CScreenshotDlg 对话框
|
|
||||||
class CScreenshotDlg : public CDialog
|
|
||||||
{
|
|
||||||
// 构造
|
|
||||||
public:
|
|
||||||
CScreenshotDlg(CWnd* pParent = NULL); // 标准构造函数
|
|
||||||
|
|
||||||
// 对话框数据
|
|
||||||
enum { IDD = IDD_SCREENSHOT_DIALOG };
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
|
||||||
|
|
||||||
|
|
||||||
// 实现
|
|
||||||
protected:
|
|
||||||
HICON m_hIcon;
|
|
||||||
|
|
||||||
// 生成的消息映射函数
|
|
||||||
virtual BOOL OnInitDialog();
|
|
||||||
afx_msg void OnPaint();
|
|
||||||
afx_msg HCURSOR OnQueryDragIcon();
|
|
||||||
DECLARE_MESSAGE_MAP()
|
|
||||||
public:
|
|
||||||
afx_msg void OnBnClickedBtnStart();
|
|
||||||
};
|
|
Before Width: | Height: | Size: 142 B |
Before Width: | Height: | Size: 172 B |
Before Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 260 B |
Before Width: | Height: | Size: 142 B |
Before Width: | Height: | Size: 146 B |
Before Width: | Height: | Size: 153 B |
Before Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 171 B |
Before Width: | Height: | Size: 21 KiB |
@ -1,13 +0,0 @@
|
|||||||
//
|
|
||||||
// Screenshot.RC2 - Microsoft Visual C++ 不会直接编辑的资源
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
#error 此文件不能用 Microsoft Visual C++ 编辑
|
|
||||||
#endif //APSTUDIO_INVOKED
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 在此处添加手动编辑的资源...
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
|
Before Width: | Height: | Size: 276 B |
Before Width: | Height: | Size: 195 B |
Before Width: | Height: | Size: 766 B |
Before Width: | Height: | Size: 151 KiB |
@ -1,33 +0,0 @@
|
|||||||
//{{NO_DEPENDENCIES}}
|
|
||||||
// Microsoft Visual C++ generated include file.
|
|
||||||
// Used by Screenshot.rc
|
|
||||||
//
|
|
||||||
#define IDD_SCREENSHOT_DIALOG 102
|
|
||||||
#define IDR_MAINFRAME 128
|
|
||||||
#define IDD_DIALOGFORIMG 129
|
|
||||||
#define IDB_BITMAP_BK 131
|
|
||||||
#define IDB_ARROW 132
|
|
||||||
#define IDC_CURSOR1 136
|
|
||||||
#define IDB_RECTANGLE 137
|
|
||||||
#define IDB_CIRCLE 138
|
|
||||||
#define IDB_BRUSH 139
|
|
||||||
#define IDB_MOSAIC 140
|
|
||||||
#define IDB_TEXT 141
|
|
||||||
#define IDB_UNDO 142
|
|
||||||
#define IDB_SAVE 143
|
|
||||||
#define IDB_EXIT 144
|
|
||||||
#define IDB_PNG2 145
|
|
||||||
#define IDB_FINISH 145
|
|
||||||
#define IDC_BTN_START 1000
|
|
||||||
#define IDC_EDIT1 1001
|
|
||||||
|
|
||||||
// Next default values for new objects
|
|
||||||
//
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 146
|
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32772
|
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1003
|
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
|
||||||
#endif
|
|
||||||
#endif
|
|
@ -1,7 +0,0 @@
|
|||||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
|
||||||
// Screenshot.pch 将作为预编译头
|
|
||||||
// stdafx.obj 将包含预编译类型信息
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
|||||||
// stdafx.h : 标准系统包含文件的包含文件,
|
|
||||||
// 或是经常使用但不常更改的
|
|
||||||
// 特定于项目的包含文件
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifndef _SECURE_ATL
|
|
||||||
#define _SECURE_ATL 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef VC_EXTRALEAN
|
|
||||||
#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "targetver.h"
|
|
||||||
|
|
||||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的
|
|
||||||
|
|
||||||
// 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏
|
|
||||||
#define _AFX_ALL_WARNINGS
|
|
||||||
|
|
||||||
#include <afxwin.h> // MFC 核心组件和标准组件
|
|
||||||
#include <afxext.h> // MFC 扩展
|
|
||||||
|
|
||||||
|
|
||||||
#include <afxdisp.h> // MFC 自动化类
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _AFX_NO_OLE_SUPPORT
|
|
||||||
#include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持
|
|
||||||
#endif
|
|
||||||
#ifndef _AFX_NO_AFXCMN_SUPPORT
|
|
||||||
#include <afxcmn.h> // MFC 对 Windows 公共控件的支持
|
|
||||||
#endif // _AFX_NO_AFXCMN_SUPPORT
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _UNICODE
|
|
||||||
#if defined _M_IX86
|
|
||||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
|
||||||
#elif defined _M_IA64
|
|
||||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
|
||||||
#elif defined _M_X64
|
|
||||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
|
||||||
#else
|
|
||||||
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// 以下宏定义要求的最低平台。要求的最低平台
|
|
||||||
// 是具有运行应用程序所需功能的 Windows、Internet Explorer 等产品的
|
|
||||||
// 最早版本。通过在指定版本及更低版本的平台上启用所有可用的功能,宏可以
|
|
||||||
// 正常工作。
|
|
||||||
|
|
||||||
// 如果必须要针对低于以下指定版本的平台,请修改下列定义。
|
|
||||||
// 有关不同平台对应值的最新信息,请参考 MSDN。
|
|
||||||
#ifndef WINVER // 指定要求的最低平台是 Windows Vista。
|
|
||||||
#define WINVER 0x0600 // 将此值更改为相应的值,以适用于 Windows 的其他版本。
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32_WINNT // 指定要求的最低平台是 Windows Vista。
|
|
||||||
#define _WIN32_WINNT 0x0600 // 将此值更改为相应的值,以适用于 Windows 的其他版本。
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32_WINDOWS // 指定要求的最低平台是 Windows 98。
|
|
||||||
#define _WIN32_WINDOWS 0x0410 // 将此值更改为适当的值,以适用于 Windows Me 或更高版本。
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _WIN32_IE // 指定要求的最低平台是 Internet Explorer 7.0。
|
|
||||||
#define _WIN32_IE 0x0700 // 将此值更改为相应的值,以适用于 IE 的其他版本。
|
|
||||||
#endif
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
rm -rf build
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j8
|
@ -0,0 +1,158 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# EasyPR auto configure script
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# This script configures OpenCV3.1 for Visual Studio
|
||||||
|
# on Windows.
|
||||||
|
#
|
||||||
|
# You are required to have Python3.* installed, and python.exe must
|
||||||
|
# be added to your PATH (C:\Python34 for example).
|
||||||
|
#
|
||||||
|
# You can use it by executing:
|
||||||
|
#
|
||||||
|
# C:\> cd path\to\EasyPR
|
||||||
|
# C:\> python configure.py
|
||||||
|
#
|
||||||
|
# Note: compatible with python3, haven't been tested on python2.
|
||||||
|
#
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
kProjectDir = "vcprojs"
|
||||||
|
|
||||||
|
kProjects = ["libeasypr.vcxproj", "demo.vcxproj"]
|
||||||
|
|
||||||
|
kProjectTemplates = ["libeasypr.vcxproj.template", "demo.vcxproj.template"]
|
||||||
|
|
||||||
|
kOpenCVConfig = "OpenCVConfig-version.cmake"
|
||||||
|
|
||||||
|
kConfig = {
|
||||||
|
"build": "",
|
||||||
|
"include": "",
|
||||||
|
"library": "",
|
||||||
|
"link": ["opencv_world310"],
|
||||||
|
"bit": "",
|
||||||
|
"vs": ""
|
||||||
|
}
|
||||||
|
|
||||||
|
kPatterns = {
|
||||||
|
"include": "(<AdditionalIncludeDirectories>)(.*?)(</AdditionalIncludeDirectories>)",
|
||||||
|
"library": "(<AdditionalLibraryDirectories>)(.*?)(</AdditionalLibraryDirectories>)",
|
||||||
|
"link": "(<AdditionalDependencies>)(.*?)(</AdditionalDependencies>)"
|
||||||
|
}
|
||||||
|
|
||||||
|
kReplacements = {
|
||||||
|
"include": r"\1%s;\2\3",
|
||||||
|
"library": r'\1%s\3',
|
||||||
|
"link": r'\1%s;\2\3'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def configure():
|
||||||
|
for i in range(2):
|
||||||
|
print(">> creating %s" % kProjects[i])
|
||||||
|
tpath = os.path.join(kProjectDir, kProjectTemplates[i])
|
||||||
|
fp = open(tpath, encoding="utf-8")
|
||||||
|
try:
|
||||||
|
# read from disk
|
||||||
|
original = fp.read()
|
||||||
|
nstring = ""
|
||||||
|
if 0 == i:
|
||||||
|
nstring = configure_libeasypr(original)
|
||||||
|
elif 1 == i:
|
||||||
|
nstring = configure_demo(original)
|
||||||
|
|
||||||
|
# write to disk
|
||||||
|
wpath = os.path.join(kProjectDir, kProjects[i])
|
||||||
|
writer = open(wpath, mode="wb")
|
||||||
|
try:
|
||||||
|
writer.write(nstring.encode())
|
||||||
|
finally:
|
||||||
|
writer.close()
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
|
print(">> all done! Open EasyPR.sln and have fun!")
|
||||||
|
|
||||||
|
|
||||||
|
def configure_libeasypr(buffer):
|
||||||
|
# additional include dir
|
||||||
|
pattern = re.compile(kPatterns["include"])
|
||||||
|
return pattern.sub(kReplacements["include"] %
|
||||||
|
(kConfig["include"][:2] + re.escape(kConfig["include"][2:])),
|
||||||
|
buffer)
|
||||||
|
|
||||||
|
|
||||||
|
def configure_demo(buffer):
|
||||||
|
# additional include dir
|
||||||
|
pattern = re.compile(kPatterns["include"])
|
||||||
|
nstring = pattern.sub(kReplacements["include"] %
|
||||||
|
(kConfig["include"][:2] + re.escape(kConfig["include"][2:])),
|
||||||
|
buffer)
|
||||||
|
# additional library dir
|
||||||
|
pattern = re.compile(kPatterns["library"])
|
||||||
|
nstring = pattern.sub(kReplacements["library"] %
|
||||||
|
(kConfig["library"][:2] + re.escape(kConfig["library"][2:])),
|
||||||
|
nstring)
|
||||||
|
# additional dependencies
|
||||||
|
#lib_string = ""
|
||||||
|
#for lib in kConfig["link"]:
|
||||||
|
# lib_string += (lib + "d.lib")
|
||||||
|
|
||||||
|
#pattern = re.compile(kPatterns["link"])
|
||||||
|
#return pattern.sub(kReplacements["link"] % lib_string, nstring)
|
||||||
|
|
||||||
|
return nstring
|
||||||
|
|
||||||
|
|
||||||
|
def check_opencv_version():
|
||||||
|
file = os.path.join(kConfig["build"], kOpenCVConfig)
|
||||||
|
print(">> Checking ", file)
|
||||||
|
fp = open(file)
|
||||||
|
opencv_version = 0
|
||||||
|
try:
|
||||||
|
fline = fp.readline()
|
||||||
|
match = re.search(r"OpenCV_VERSION (\d)\.(\d)\.(\d{,2})", fline)
|
||||||
|
if match is not None:
|
||||||
|
opencv_version = match.group(1) + "." + match.group(2)
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
|
return opencv_version
|
||||||
|
|
||||||
|
|
||||||
|
def cli():
|
||||||
|
while True:
|
||||||
|
root_ = input(r"Where is your opencv root path? (e.g, C:\path\to\opencv3): ")
|
||||||
|
if os.path.exists(root_):
|
||||||
|
kConfig["build"] = os.path.join(root_, "build")
|
||||||
|
kConfig["include"] = os.path.join(kConfig["build"], "include")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid path")
|
||||||
|
|
||||||
|
if check_opencv_version() != "3.1":
|
||||||
|
print("requires opencv 3.1")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
kConfig["bit"] = "x64"
|
||||||
|
|
||||||
|
while True:
|
||||||
|
vc = input("Which Visual Studio you are using? (vs2013 or vs2015): ")
|
||||||
|
if vc == "vs2013":
|
||||||
|
kConfig["vs"] = "vc12"
|
||||||
|
break
|
||||||
|
elif vc == "vs2015":
|
||||||
|
kConfig["vs"] = "vc14"
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Please type vs2013 or vs2015")
|
||||||
|
|
||||||
|
kConfig["library"] = os.path.normpath("%s/%s/%s/lib/" % (kConfig["build"], kConfig["bit"], kConfig["vs"]))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
cli()
|
||||||
|
configure()
|
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef EASYPR_EASYPR_H
|
||||||
|
#define EASYPR_EASYPR_H
|
||||||
|
|
||||||
|
#include "easypr/core/plate_recognize.h"
|
||||||
|
#include "easypr/train/svm_train.h"
|
||||||
|
#include "easypr/train/ann_train.h"
|
||||||
|
#include "easypr/train/annCh_train.h"
|
||||||
|
#include "easypr/util/util.h"
|
||||||
|
#include "easypr/util/program_options.h"
|
||||||
|
#include "easypr/api.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
#endif //EASYPR_EASYPR_H
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* This file provides some of the most commonly used application interfaces.
|
||||||
|
*/
|
||||||
|
#ifndef EASYPR_API_HPP
|
||||||
|
#define EASYPR_API_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
static bool plate_judge(const char* image, const char* model) {
|
||||||
|
cv::Mat src = cv::imread(image);
|
||||||
|
assert(!src.empty());
|
||||||
|
|
||||||
|
int result;
|
||||||
|
result = PlateJudge::instance()->plateJudge(src);
|
||||||
|
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void plate_locate(const char* image, const bool life_mode = true) {
|
||||||
|
cv::Mat src = cv::imread(image);
|
||||||
|
|
||||||
|
assert(!src.empty());
|
||||||
|
|
||||||
|
CPlateLocate plate;
|
||||||
|
plate.setDebug(1);
|
||||||
|
plate.setLifemode(life_mode);
|
||||||
|
|
||||||
|
std::vector<cv::Mat> results;
|
||||||
|
plate.plateLocate(src, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::vector<std::string> plate_recognize(const char* image,
|
||||||
|
const char* model_svm,
|
||||||
|
const char* model_ann,
|
||||||
|
const bool life_mode = true) {
|
||||||
|
cv::Mat img = cv::imread(image);
|
||||||
|
assert(!img.empty());
|
||||||
|
|
||||||
|
CPlateRecognize pr;
|
||||||
|
pr.setResultShow(false);
|
||||||
|
pr.setLifemode(true);
|
||||||
|
pr.setMaxPlates(1);
|
||||||
|
pr.setDetectType(PR_DETECT_CMSER | PR_DETECT_COLOR);
|
||||||
|
|
||||||
|
std::vector<std::string> results;
|
||||||
|
std::vector<CPlate> plates;
|
||||||
|
pr.plateRecognize(img, plates, 0);
|
||||||
|
|
||||||
|
for (auto plate : plates) {
|
||||||
|
results.push_back(plate.getPlateStr());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plates.size() == 1) {
|
||||||
|
if (1) {
|
||||||
|
std::stringstream ss(std::stringstream::in | std::stringstream::out);
|
||||||
|
ss << "result.jpg";
|
||||||
|
imwrite(ss.str(), plates.at(0).getPlateMat());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::move(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Color get_plate_color(const char* image) {
|
||||||
|
cv::Mat img = cv::imread(image);
|
||||||
|
|
||||||
|
assert(!img.empty());
|
||||||
|
|
||||||
|
return getPlateType(img, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_API_HPP
|
@ -0,0 +1,148 @@
|
|||||||
|
#ifndef EASYPR_CONFIG_H_
|
||||||
|
#define EASYPR_CONFIG_H_
|
||||||
|
|
||||||
|
#define CV_VERSION_THREE_ZERO
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
enum Color { BLUE, YELLOW, WHITE, UNKNOWN };
|
||||||
|
|
||||||
|
enum LocateType { SOBEL, COLOR, CMSER, OTHER };
|
||||||
|
|
||||||
|
enum CharSearchDirection { LEFT, RIGHT };
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PR_MODE_UNCONSTRAINED,
|
||||||
|
PR_MODE_CAMERPOHNE,
|
||||||
|
PR_MODE_PARKING,
|
||||||
|
PR_MODE_HIGHWAY
|
||||||
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PR_DETECT_SOBEL = 0x01, /**Sobel detect type, using twice Sobel */
|
||||||
|
PR_DETECT_COLOR = 0x02, /**Color detect type */
|
||||||
|
PR_DETECT_CMSER = 0x04, /**Character detect type, using mser */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* kDefaultSvmPath = "model/svm_hist.xml";
|
||||||
|
static const char* kLBPSvmPath = "model/svm_lbp.xml";
|
||||||
|
static const char* kHistSvmPath = "model/svm_hist.xml";
|
||||||
|
|
||||||
|
static const char* kDefaultAnnPath = "model/ann.xml";
|
||||||
|
static const char* kChineseAnnPath = "model/ann_chinese.xml";
|
||||||
|
static const char* kGrayAnnPath = "model/annCh.xml";
|
||||||
|
|
||||||
|
//This is important to for key transform to chinese
|
||||||
|
static const char* kChineseMappingPath = "model/province_mapping";
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kForward = 1, // correspond to "has plate"
|
||||||
|
kInverse = 0 // correspond to "no plate"
|
||||||
|
} SvmLabel;
|
||||||
|
|
||||||
|
static const int kPlateResizeWidth = 136;
|
||||||
|
static const int kPlateResizeHeight = 36;
|
||||||
|
|
||||||
|
static const int kShowWindowWidth = 1000;
|
||||||
|
static const int kShowWindowHeight = 800;
|
||||||
|
|
||||||
|
static const float kSvmPercentage = 0.7f;
|
||||||
|
|
||||||
|
static const int kCharacterInput = 120;
|
||||||
|
static const int kChineseInput = 440;
|
||||||
|
static const int kAnnInput = kCharacterInput;
|
||||||
|
|
||||||
|
static const int kCharacterSize = 10;
|
||||||
|
static const int kChineseSize = 20;
|
||||||
|
static const int kPredictSize = kCharacterSize;
|
||||||
|
|
||||||
|
static const int kNeurons = 40;
|
||||||
|
|
||||||
|
static const char *kChars[] = {
|
||||||
|
"0", "1", "2",
|
||||||
|
"3", "4", "5",
|
||||||
|
"6", "7", "8",
|
||||||
|
"9",
|
||||||
|
/* 10 */
|
||||||
|
"A", "B", "C",
|
||||||
|
"D", "E", "F",
|
||||||
|
"G", "H", /* {"I", "I"} */
|
||||||
|
"J", "K", "L",
|
||||||
|
"M", "N", /* {"O", "O"} */
|
||||||
|
"P", "Q", "R",
|
||||||
|
"S", "T", "U",
|
||||||
|
"V", "W", "X",
|
||||||
|
"Y", "Z",
|
||||||
|
/* 24 */
|
||||||
|
"zh_cuan" , "zh_e" , "zh_gan" ,
|
||||||
|
"zh_gan1" , "zh_gui" , "zh_gui1" ,
|
||||||
|
"zh_hei" , "zh_hu" , "zh_ji" ,
|
||||||
|
"zh_jin" , "zh_jing" , "zh_jl" ,
|
||||||
|
"zh_liao" , "zh_lu" , "zh_meng" ,
|
||||||
|
"zh_min" , "zh_ning" , "zh_qing" ,
|
||||||
|
"zh_qiong", "zh_shan" , "zh_su" ,
|
||||||
|
"zh_sx" , "zh_wan" , "zh_xiang",
|
||||||
|
"zh_xin" , "zh_yu" , "zh_yu1" ,
|
||||||
|
"zh_yue" , "zh_yun" , "zh_zang" ,
|
||||||
|
"zh_zhe"
|
||||||
|
/* 31 */
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int kCharactersNumber = 34;
|
||||||
|
static const int kChineseNumber = 31;
|
||||||
|
static const int kCharsTotalNumber = 65;
|
||||||
|
|
||||||
|
static bool kDebug = false;
|
||||||
|
|
||||||
|
static const int kGrayCharWidth = 20;
|
||||||
|
static const int kGrayCharHeight = 32;
|
||||||
|
static const int kCharLBPGridX = 4;
|
||||||
|
static const int kCharLBPGridY = 4;
|
||||||
|
static const int kCharLBPPatterns = 16;
|
||||||
|
|
||||||
|
static const int kCharHiddenNeurans = 64;
|
||||||
|
|
||||||
|
static const int kCharsCountInOnePlate = 7;
|
||||||
|
static const int kSymbolsCountInChinesePlate = 6;
|
||||||
|
|
||||||
|
static const float kPlateMaxSymbolCount = 7.5f;
|
||||||
|
static const int kSymbolIndex = 2;
|
||||||
|
|
||||||
|
// Disable the copy and assignment operator for this class.
|
||||||
|
#define DISABLE_ASSIGN_AND_COPY(className) \
|
||||||
|
private:\
|
||||||
|
className& operator=(const className&); \
|
||||||
|
className(const className&)
|
||||||
|
|
||||||
|
// Display the image.
|
||||||
|
#define SET_DEBUG(param) \
|
||||||
|
kDebug = param
|
||||||
|
|
||||||
|
// Display the image.
|
||||||
|
#define SHOW_IMAGE(imgName, debug) \
|
||||||
|
if (debug) { \
|
||||||
|
namedWindow("imgName", WINDOW_AUTOSIZE); \
|
||||||
|
moveWindow("imgName", 500, 500); \
|
||||||
|
imshow("imgName", imgName); \
|
||||||
|
waitKey(0); \
|
||||||
|
destroyWindow("imgName"); \
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load model. compatitable withe 3.0, 3.1 and 3.2
|
||||||
|
#ifdef CV_VERSION_THREE_TWO
|
||||||
|
#define LOAD_SVM_MODEL(model, path) \
|
||||||
|
model = ml::SVM::load(path);
|
||||||
|
#define LOAD_ANN_MODEL(model, path) \
|
||||||
|
model = ml::ANN_MLP::load(path);
|
||||||
|
#else
|
||||||
|
#define LOAD_SVM_MODEL(model, path) \
|
||||||
|
model = ml::SVM::load<ml::SVM>(path);
|
||||||
|
#define LOAD_ANN_MODEL(model, path) \
|
||||||
|
model = ml::ANN_MLP::load<ml::ANN_MLP>(path);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_CONFIG_H_
|
@ -0,0 +1,131 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: CHARACTER Header
|
||||||
|
// Version: 1.0
|
||||||
|
// Date: 2016-06-14
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Desciption:
|
||||||
|
// An abstract class for car character in plate.
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_CHARACTER_H_
|
||||||
|
#define EASYPR_CORE_CHARACTER_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CCharacter {
|
||||||
|
public:
|
||||||
|
CCharacter()
|
||||||
|
{
|
||||||
|
m_characterMat = Mat();
|
||||||
|
m_characterGrayMat = Mat();
|
||||||
|
m_characterPos = Rect();
|
||||||
|
m_characterStr = "";
|
||||||
|
m_score = 0;
|
||||||
|
m_isChinese = false;
|
||||||
|
m_ostuLevel = 125;
|
||||||
|
m_center = Point(0, 0);
|
||||||
|
m_index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCharacter(const CCharacter& other)
|
||||||
|
{
|
||||||
|
m_characterMat = other.m_characterMat;
|
||||||
|
m_characterGrayMat = other.m_characterGrayMat;
|
||||||
|
m_characterPos = other.m_characterPos;
|
||||||
|
m_characterStr = other.m_characterStr;
|
||||||
|
m_score = other.m_score;
|
||||||
|
m_isChinese = other.m_isChinese;
|
||||||
|
m_ostuLevel = other.m_ostuLevel;
|
||||||
|
m_center = other.m_center;
|
||||||
|
m_index = other.m_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setCharacterMat(Mat param) { m_characterMat = param; }
|
||||||
|
inline Mat getCharacterMat() const { return m_characterMat; }
|
||||||
|
|
||||||
|
inline void setCharacterGrayMat(Mat param) { m_characterGrayMat = param; }
|
||||||
|
inline Mat getCharacterGrayMat() const { return m_characterGrayMat; }
|
||||||
|
|
||||||
|
inline void setCharacterPos(Rect param) { m_characterPos = param; }
|
||||||
|
inline Rect getCharacterPos() const { return m_characterPos; }
|
||||||
|
|
||||||
|
inline void setCharacterStr(String param) { m_characterStr = param; }
|
||||||
|
inline String getCharacterStr() const { return m_characterStr; }
|
||||||
|
|
||||||
|
inline void setCharacterScore(double param) { m_score = param; }
|
||||||
|
inline double getCharacterScore() const { return m_score; }
|
||||||
|
|
||||||
|
inline void setIsChinese(bool param) { m_isChinese = param; }
|
||||||
|
inline bool getIsChinese() const { return m_isChinese; }
|
||||||
|
|
||||||
|
inline void setOstuLevel(double param) { m_ostuLevel = param; }
|
||||||
|
inline double getOstuLevel() const { return m_ostuLevel; }
|
||||||
|
|
||||||
|
inline void setCenterPoint(Point param) { m_center = param; }
|
||||||
|
inline Point getCenterPoint() const { return m_center; }
|
||||||
|
|
||||||
|
inline void setIndex(int param) { m_index = param; }
|
||||||
|
inline int getIndex() const { return m_index; }
|
||||||
|
|
||||||
|
inline bool getIsStrong() const { return m_score >= 0.9; }
|
||||||
|
inline bool getIsWeak() const { return m_score < 0.9 && m_score >= 0.5; }
|
||||||
|
inline bool getIsLittle() const { return m_score < 0.5; }
|
||||||
|
|
||||||
|
bool operator < (const CCharacter& other) const
|
||||||
|
{
|
||||||
|
return (m_score > other.m_score);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator < (const CCharacter& other)
|
||||||
|
{
|
||||||
|
return (m_score > other.m_score);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! character mat
|
||||||
|
Mat m_characterMat;
|
||||||
|
|
||||||
|
//! character gray mat
|
||||||
|
Mat m_characterGrayMat;
|
||||||
|
|
||||||
|
//! character rect
|
||||||
|
Rect m_characterPos;
|
||||||
|
|
||||||
|
//! character str
|
||||||
|
String m_characterStr;
|
||||||
|
|
||||||
|
//! character likely
|
||||||
|
double m_score;
|
||||||
|
|
||||||
|
//! weather is chinese
|
||||||
|
bool m_isChinese;
|
||||||
|
|
||||||
|
//! ostu level
|
||||||
|
double m_ostuLevel;
|
||||||
|
|
||||||
|
//! center point
|
||||||
|
Point m_center;
|
||||||
|
|
||||||
|
//! the postion in the plate, from 1 to 7 normal
|
||||||
|
int m_index;
|
||||||
|
|
||||||
|
////! m_score >= 0.9
|
||||||
|
//bool isStrong;
|
||||||
|
|
||||||
|
////! m_score < 0.9 && m_score >= 0.5
|
||||||
|
//bool isWeak;
|
||||||
|
|
||||||
|
////! m_score < 0.5
|
||||||
|
//bool isLittle;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATE_H_
|
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef EASYPR_CORE_CHARSIDENTIFY_H_
|
||||||
|
#define EASYPR_CORE_CHARSIDENTIFY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
|
||||||
|
#include "easypr/util/kv.h"
|
||||||
|
#include "easypr/core/character.hpp"
|
||||||
|
#include "easypr/core/feature.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CharsIdentify {
|
||||||
|
public:
|
||||||
|
static CharsIdentify* instance();
|
||||||
|
|
||||||
|
int classify(cv::Mat f, float& maxVal, bool isChinses = false, bool isAlphabet = false);
|
||||||
|
void classify(cv::Mat featureRows, std::vector<int>& out_maxIndexs,
|
||||||
|
std::vector<float>& out_maxVals, std::vector<bool> isChineseVec);
|
||||||
|
void classify(std::vector<CCharacter>& charVec);
|
||||||
|
|
||||||
|
void classifyChinese(std::vector<CCharacter>& charVec);
|
||||||
|
void classifyChineseGray(std::vector<CCharacter>& charVec);
|
||||||
|
|
||||||
|
std::pair<std::string, std::string> identify(cv::Mat input, bool isChinese = false, bool isAlphabet = false);
|
||||||
|
int identify(std::vector<cv::Mat> inputs, std::vector<std::pair<std::string, std::string>>& outputs,
|
||||||
|
std::vector<bool> isChineseVec);
|
||||||
|
|
||||||
|
std::pair<std::string, std::string> identifyChinese(cv::Mat input, float& result, bool& isChinese);
|
||||||
|
std::pair<std::string, std::string> identifyChineseGray(cv::Mat input, float& result, bool& isChinese);
|
||||||
|
|
||||||
|
bool isCharacter(cv::Mat input, std::string& label, float& maxVal, bool isChinese = false);
|
||||||
|
|
||||||
|
void LoadModel(std::string path);
|
||||||
|
void LoadChineseModel(std::string path);
|
||||||
|
void LoadGrayChANN(std::string path);
|
||||||
|
void LoadChineseMapping(std::string path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CharsIdentify();
|
||||||
|
annCallback extractFeature;
|
||||||
|
static CharsIdentify* instance_;
|
||||||
|
|
||||||
|
// binary character classifer
|
||||||
|
cv::Ptr<cv::ml::ANN_MLP> ann_;
|
||||||
|
|
||||||
|
// binary character classifer, only for chinese
|
||||||
|
cv::Ptr<cv::ml::ANN_MLP> annChinese_;
|
||||||
|
|
||||||
|
// gray classifer, only for chinese
|
||||||
|
cv::Ptr<cv::ml::ANN_MLP> annGray_;
|
||||||
|
|
||||||
|
// used for chinese mapping
|
||||||
|
std::shared_ptr<Kv> kv_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_CHARSIDENTIFY_H_
|
@ -0,0 +1,83 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: chars_recognise Header
|
||||||
|
// Version: 1.0
|
||||||
|
// Date: 2014-09-28
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Reference: Mastering OpenCV with Practical Computer Vision Projects
|
||||||
|
// Reference: CSDN Bloger taotao1233
|
||||||
|
// Desciption:
|
||||||
|
// Defines CCharsRecognise
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_CHARSRECOGNISE_H_
|
||||||
|
#define EASYPR_CORE_CHARSRECOGNISE_H_
|
||||||
|
|
||||||
|
#include "easypr/core/chars_segment.h"
|
||||||
|
#include "easypr/core/chars_identify.h"
|
||||||
|
#include "easypr/core/core_func.h"
|
||||||
|
#include "easypr/util/util.h"
|
||||||
|
#include "easypr/core/plate.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CCharsRecognise {
|
||||||
|
public:
|
||||||
|
CCharsRecognise();
|
||||||
|
|
||||||
|
~CCharsRecognise();
|
||||||
|
|
||||||
|
int charsRecognise(cv::Mat plate, std::string& plateLicense);
|
||||||
|
int charsRecognise(CPlate& plate, std::string& plateLicense);
|
||||||
|
|
||||||
|
inline std::string getPlateColor(cv::Mat input) const {
|
||||||
|
std::string color = "未知";
|
||||||
|
Color result = getPlateType(input, true);
|
||||||
|
if (BLUE == result) color = "蓝牌";
|
||||||
|
if (YELLOW == result) color = "黄牌";
|
||||||
|
if (WHITE == result) color = "白牌";
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
color = utils::utf8_to_gbk(color.c_str());
|
||||||
|
#endif
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string getPlateColor(Color in) const {
|
||||||
|
std::string color = "未知";
|
||||||
|
if (BLUE == in) color = "蓝牌";
|
||||||
|
if (YELLOW == in) color = "黄牌";
|
||||||
|
if (WHITE == in) color = "白牌";
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
color = utils::utf8_to_gbk(color.c_str());
|
||||||
|
#endif
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setLiuDingSize(int param) {
|
||||||
|
m_charsSegment->setLiuDingSize(param);
|
||||||
|
}
|
||||||
|
inline void setColorThreshold(int param) {
|
||||||
|
m_charsSegment->setColorThreshold(param);
|
||||||
|
}
|
||||||
|
inline void setBluePercent(float param) {
|
||||||
|
m_charsSegment->setBluePercent(param);
|
||||||
|
}
|
||||||
|
inline float getBluePercent() const {
|
||||||
|
return m_charsSegment->getBluePercent();
|
||||||
|
}
|
||||||
|
inline void setWhitePercent(float param) {
|
||||||
|
m_charsSegment->setWhitePercent(param);
|
||||||
|
}
|
||||||
|
inline float getWhitePercent() const {
|
||||||
|
return m_charsSegment->getWhitePercent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
//!字符分割
|
||||||
|
|
||||||
|
CCharsSegment* m_charsSegment;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* \namespace easypr */
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_CHARSRECOGNISE_H_
|
@ -0,0 +1,84 @@
|
|||||||
|
#ifndef EASYPR_CORE_CHARSSEGMENT_H_
|
||||||
|
#define EASYPR_CORE_CHARSSEGMENT_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CCharsSegment {
|
||||||
|
public:
|
||||||
|
CCharsSegment();
|
||||||
|
//! using ostu algotithm the segment chars in plate
|
||||||
|
int charsSegment(Mat input, std::vector<Mat>& resultVec, Color color = BLUE);
|
||||||
|
|
||||||
|
//! using methods to segment chars in plate
|
||||||
|
int charsSegmentUsingOSTU(Mat input, std::vector<Mat>& resultVec, std::vector<Mat>& grayChars, Color color = BLUE);
|
||||||
|
int charsSegmentUsingMSER(Mat input, vector<Mat>& resultVec, vector<Mat>& grayChars, Color color = BLUE);
|
||||||
|
|
||||||
|
//! using project
|
||||||
|
int projectSegment(const Mat& input, Color color, vector<int>& out_indexs);
|
||||||
|
|
||||||
|
bool verifyCharSizes(Mat r);
|
||||||
|
|
||||||
|
// find the best chinese binaranzation method
|
||||||
|
void judgeChinese(Mat in, Mat& out, Color plateType);
|
||||||
|
void judgeChineseGray(Mat in, Mat& out, Color plateType);
|
||||||
|
|
||||||
|
Mat preprocessChar(Mat in);
|
||||||
|
|
||||||
|
//! to find the position of chinese
|
||||||
|
Rect GetChineseRect(const Rect rectSpe);
|
||||||
|
|
||||||
|
//! find the character refer to city, like "suA" A
|
||||||
|
int GetSpecificRect(const std::vector<Rect>& vecRect);
|
||||||
|
|
||||||
|
//! Do two things
|
||||||
|
// 1.remove rect in the left of city character
|
||||||
|
// 2.from the city rect, to the right, choose 6 rects
|
||||||
|
int RebuildRect(const std::vector<Rect>& vecRect, std::vector<Rect>& outRect,
|
||||||
|
int specIndex);
|
||||||
|
|
||||||
|
int SortRect(const std::vector<Rect>& vecRect, std::vector<Rect>& out);
|
||||||
|
|
||||||
|
inline void setLiuDingSize(int param) { m_LiuDingSize = param; }
|
||||||
|
inline void setColorThreshold(int param) { m_ColorThreshold = param; }
|
||||||
|
|
||||||
|
inline void setBluePercent(float param) { m_BluePercent = param; }
|
||||||
|
inline float getBluePercent() const { return m_BluePercent; }
|
||||||
|
inline void setWhitePercent(float param) { m_WhitePercent = param; }
|
||||||
|
inline float getWhitePercent() const { return m_WhitePercent; }
|
||||||
|
|
||||||
|
static const int DEFAULT_DEBUG = 1;
|
||||||
|
|
||||||
|
static const int CHAR_SIZE = 20;
|
||||||
|
static const int HORIZONTAL = 1;
|
||||||
|
static const int VERTICAL = 0;
|
||||||
|
|
||||||
|
static const int DEFAULT_LIUDING_SIZE = 7;
|
||||||
|
static const int DEFAULT_MAT_WIDTH = 136;
|
||||||
|
static const int DEFAULT_COLORTHRESHOLD = 150;
|
||||||
|
|
||||||
|
inline void setDebug(int param) { m_debug = param; }
|
||||||
|
|
||||||
|
inline int getDebug() { return m_debug; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_LiuDingSize;
|
||||||
|
|
||||||
|
int m_theMatWidth;
|
||||||
|
|
||||||
|
int m_ColorThreshold;
|
||||||
|
float m_BluePercent;
|
||||||
|
float m_WhitePercent;
|
||||||
|
|
||||||
|
int m_debug;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_CHARSSEGMENT_H_
|
@ -0,0 +1,159 @@
|
|||||||
|
#ifndef EASYPR_CORE_COREFUNC_H_
|
||||||
|
#define EASYPR_CORE_COREFUNC_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "easypr/core/plate.hpp"
|
||||||
|
#include "easypr/core/character.hpp"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
//! find binary image match to color
|
||||||
|
//! input rgb, want match color ( blue or yellow)
|
||||||
|
//! out grey, 255 is match, 0 is not match
|
||||||
|
|
||||||
|
Mat colorMatch(const Mat& src, Mat& match, const Color r,
|
||||||
|
const bool adaptive_minsv);
|
||||||
|
|
||||||
|
//Mat mserMatch(const Mat& src, Mat& match, const Color r,
|
||||||
|
// std::vector<RotatedRect>& plateRect, std::vector<Rect>& out_charRect);
|
||||||
|
|
||||||
|
bool plateColorJudge(const Mat& src, const Color r, const bool adaptive_minsv,
|
||||||
|
float& percent);
|
||||||
|
|
||||||
|
bool bFindLeftRightBound(Mat& bound_threshold, int& posLeft, int& posRight);
|
||||||
|
bool bFindLeftRightBound1(Mat& bound_threshold, int& posLeft, int& posRight);
|
||||||
|
bool bFindLeftRightBound2(Mat& bound_threshold, int& posLeft, int& posRight);
|
||||||
|
|
||||||
|
bool clearLiuDing(Mat& img);
|
||||||
|
void clearLiuDingOnly(Mat& img);
|
||||||
|
void clearLiuDing(Mat mask, int& top, int& bottom);
|
||||||
|
|
||||||
|
Color getPlateType(const Mat& src, const bool adaptive_minsv);
|
||||||
|
|
||||||
|
Mat histeq(Mat in);
|
||||||
|
Rect GetCenterRect(Mat& in);
|
||||||
|
Mat CutTheRect(Mat& in, Rect& rect);
|
||||||
|
int ThresholdOtsu(Mat mat);
|
||||||
|
|
||||||
|
// project histogram
|
||||||
|
Mat ProjectedHistogram(Mat img, int t, int threshold = 20);
|
||||||
|
|
||||||
|
Mat showHistogram(const Mat& hist);
|
||||||
|
|
||||||
|
Mat preprocessChar(Mat in, int char_size);
|
||||||
|
|
||||||
|
Rect GetChineseRect(const Rect rectSpe);
|
||||||
|
|
||||||
|
bool verifyCharSizes(Rect r);
|
||||||
|
bool verifyPlateSize(Rect mr);
|
||||||
|
bool verifyRotatedPlateSizes(RotatedRect mr, bool showDebug = false);
|
||||||
|
|
||||||
|
// non-maximum suppression
|
||||||
|
void NMStoCharacter(std::vector<CCharacter> &inVec, double overlap);
|
||||||
|
|
||||||
|
// draw rotatedRectangle
|
||||||
|
void rotatedRectangle(InputOutputArray img, RotatedRect rect,
|
||||||
|
const Scalar& color, int thickness = 1,
|
||||||
|
int lineType = LINE_8, int shift = 0);
|
||||||
|
|
||||||
|
// ostu region
|
||||||
|
void spatial_ostu(InputArray _src, int grid_x, int grid_y, Color type = BLUE);
|
||||||
|
|
||||||
|
// Scale to small image (for the purpose of comput mser in large image)
|
||||||
|
Mat scaleImage(const Mat& image, const Size& maxSize, double& scale_ratio);
|
||||||
|
|
||||||
|
// Scale back RotatedRect
|
||||||
|
RotatedRect scaleBackRRect(const RotatedRect& rr, const float scale_ratio);
|
||||||
|
|
||||||
|
//! use verify size to first generate char candidates
|
||||||
|
void mserCharMatch(const Mat &src, std::vector<Mat> &match, std::vector<CPlate>& out_plateVec_blue, std::vector<CPlate>& out_plateVec_yellow,
|
||||||
|
bool usePlateMser, std::vector<RotatedRect>& out_plateRRect_blue, std::vector<RotatedRect>& out_plateRRect_yellow, int index = 0, bool showDebug = false);
|
||||||
|
|
||||||
|
// computer the insert over union about two rrect
|
||||||
|
bool computeIOU(const RotatedRect& rrect1, const RotatedRect& rrect2, const int width, const int height, const float thresh, float& result);
|
||||||
|
float computeIOU(const RotatedRect& rrect1, const RotatedRect& rrect2, const int width, const int height);
|
||||||
|
|
||||||
|
bool computeIOU(const Rect& rect1, const Rect& rect2, const float thresh, float& result);
|
||||||
|
float computeIOU(const Rect& rect1, const Rect& rect2);
|
||||||
|
|
||||||
|
/** @brief convert form mser point to image.
|
||||||
|
|
||||||
|
The function created first by Hailiang Xu.
|
||||||
|
Modified by Ruoze Liu.
|
||||||
|
|
||||||
|
@param
|
||||||
|
*/
|
||||||
|
Mat adaptive_image_from_points(const std::vector<Point>& points,
|
||||||
|
const Rect& rect, const Size& size, const Scalar& backgroundColor = Scalar(0, 0, 0),
|
||||||
|
const Scalar& forgroundColor = Scalar(255, 255, 255), bool gray = true);
|
||||||
|
|
||||||
|
// Calculate a rect have same length and width and remains the center
|
||||||
|
Rect adaptive_charrect_from_rect(const Rect& rect, int maxwidth, int maxheight, bool useExtendHeight = false);
|
||||||
|
|
||||||
|
// calc safe rect
|
||||||
|
bool calcSafeRect(const RotatedRect& roi_rect, const Mat& src,
|
||||||
|
Rect_<float>& safeBoundRect);
|
||||||
|
bool calcSafeRect(const RotatedRect &roi_rect, const int width, const int height,
|
||||||
|
Rect_<float> &safeBoundRect);
|
||||||
|
|
||||||
|
// uniform resize all the image to same size for the next process
|
||||||
|
Mat uniformResize(const Mat &result, float& scale);
|
||||||
|
|
||||||
|
// uniform resize all the plates to same size for the next process
|
||||||
|
Mat uniformResizePlates(const Mat &result, float& scale);
|
||||||
|
|
||||||
|
// show detect results
|
||||||
|
void showDectectResults(const Mat& img, const std::vector<CPlate> &plateVec, size_t num);
|
||||||
|
|
||||||
|
// show the results
|
||||||
|
Mat showResult(const Mat &result, int img_index = 0);
|
||||||
|
|
||||||
|
// enlarge the char rect
|
||||||
|
Rect rectEnlarge(const Rect& src, const int mat_width, const int mat_height);
|
||||||
|
Rect rectFit(const Rect &src, const int mat_width, const int mat_height);
|
||||||
|
|
||||||
|
// write images to temp folder
|
||||||
|
void writeTempImage(const Mat& outImg, const string path, int index = 0);
|
||||||
|
|
||||||
|
// remove small hor lines in the plate
|
||||||
|
bool judegMDOratio2(const Mat &image, const Rect &rect, std::vector<Point> &contour, Mat &result, const float thresh = 1.f,
|
||||||
|
bool useExtendHeight = false);
|
||||||
|
|
||||||
|
// clear top and bottom borders
|
||||||
|
void clearBorder(const Mat &img, Rect& cropRect);
|
||||||
|
|
||||||
|
//! non-maximum surpresion for 1d array
|
||||||
|
template<typename T>
|
||||||
|
void NMSfor1D(const vector<T>& arr, vector<int>& index) {
|
||||||
|
// prepare
|
||||||
|
int size = (int)arr.size();
|
||||||
|
index.resize(size);
|
||||||
|
for (int j = 0; j < size; j++)
|
||||||
|
index.at(j) = 0;
|
||||||
|
|
||||||
|
// nms
|
||||||
|
int i = 1;
|
||||||
|
while (i < size - 1) {
|
||||||
|
if (arr.at(i) > arr.at(i + 1)) {
|
||||||
|
if (arr.at(i) >= arr.at(i - 1))
|
||||||
|
index.at(i) = 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
while (i < size - 1 && arr.at(i) <= arr.at(i + 1))
|
||||||
|
i = i + 1;
|
||||||
|
if (i < size - 1)
|
||||||
|
index.at(i) = 1;
|
||||||
|
}
|
||||||
|
i = i + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_COREFUNC_H_
|
@ -0,0 +1,59 @@
|
|||||||
|
#ifndef EASYPR_CORE_FEATURE_H_
|
||||||
|
#define EASYPR_CORE_FEATURE_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
//! 获得车牌的特征数
|
||||||
|
cv::Mat getHistogram(cv::Mat in);
|
||||||
|
|
||||||
|
//! EasyPR的getFeatures回调函数
|
||||||
|
//! 用于从车牌的image生成svm的训练特征features
|
||||||
|
typedef void (*svmCallback)(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! EasyPR的getFeatures回调函数
|
||||||
|
//! convert from images to features used by gray char ann
|
||||||
|
typedef void (*annCallback)(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! gray and project feature
|
||||||
|
void getGrayPlusProject(const cv::Mat& grayChar, cv::Mat& features);
|
||||||
|
|
||||||
|
//! EasyPR的getFeatures回调函数
|
||||||
|
//! 本函数是获取垂直和水平的直方图图值
|
||||||
|
void getHistogramFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! 本函数是获取SIFT特征子
|
||||||
|
void getSIFTFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! 本函数是获取HOG特征子
|
||||||
|
void getHOGFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! 本函数是获取HSV空间量化的直方图特征子
|
||||||
|
void getHSVHistFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! LBP feature
|
||||||
|
void getLBPFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! color feature
|
||||||
|
void getColorFeatures(const cv::Mat& src, cv::Mat& features);
|
||||||
|
|
||||||
|
//! color feature and histom
|
||||||
|
void getHistomPlusColoFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! get character feature
|
||||||
|
cv::Mat charFeatures(cv::Mat in, int sizeData);
|
||||||
|
cv::Mat charFeatures2(cv::Mat in, int sizeData);
|
||||||
|
|
||||||
|
//! LBP feature + Histom feature
|
||||||
|
void getLBPplusHistFeatures(const cv::Mat& image, cv::Mat& features);
|
||||||
|
|
||||||
|
//! grayChar feauter
|
||||||
|
void getGrayCharFeatures(const cv::Mat& grayChar, cv::Mat& features);
|
||||||
|
|
||||||
|
void getGrayPlusLBP(const Mat& grayChar, Mat& features);
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_FEATURE_H_
|
@ -0,0 +1,96 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: params Header
|
||||||
|
// Version: 1.0
|
||||||
|
// Date: 2016-07-01
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Desciption:
|
||||||
|
// An abstract class for runtime algorithm params in easypr.
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_PARAMS_H_
|
||||||
|
#define EASYPR_CORE_PARAMS_H_
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CParams {
|
||||||
|
public:
|
||||||
|
static CParams* instance();
|
||||||
|
|
||||||
|
CParams(const CParams& other) {
|
||||||
|
m_isUpdate = other.m_isUpdate;
|
||||||
|
|
||||||
|
m_param1f = other.m_param1f;
|
||||||
|
m_param2f = other.m_param2f;
|
||||||
|
m_param3f = other.m_param3f;
|
||||||
|
|
||||||
|
m_param1i = other.m_param1i;
|
||||||
|
m_param2i = other.m_param2i;
|
||||||
|
m_param3i = other.m_param3i;
|
||||||
|
|
||||||
|
m_param1b = other.m_param1b;
|
||||||
|
m_param2b = other.m_param2b;
|
||||||
|
m_param3b = other.m_param3b;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setIsUpdate(bool param) { m_isUpdate = param; }
|
||||||
|
inline bool getIsUpdate() const { return m_isUpdate; }
|
||||||
|
|
||||||
|
inline void setParam1f(float param) { m_param1f = param; }
|
||||||
|
inline float getParam1f() const { return m_param1f; }
|
||||||
|
|
||||||
|
inline void setParam2f(float param) { m_param2f = param; }
|
||||||
|
inline float getParam2f() const { return m_param2f; }
|
||||||
|
|
||||||
|
inline void setParam3f(float param) { m_param3f = param; }
|
||||||
|
inline float getParam3f() const { return m_param3f; }
|
||||||
|
|
||||||
|
inline void setParam1i(int param) { m_param1i = param; }
|
||||||
|
inline int getParam1i() const { return m_param1i; }
|
||||||
|
|
||||||
|
inline void setParam2i(int param) { m_param2i = param; }
|
||||||
|
inline int getParam2i() const { return m_param2i; }
|
||||||
|
|
||||||
|
inline void setParam3i(int param) { m_param3i = param; }
|
||||||
|
inline int getParam3i() const { return m_param3i; }
|
||||||
|
|
||||||
|
inline void setParam1b(bool param) { m_param1b = param; }
|
||||||
|
inline bool getParam1b() const { return m_param1b; }
|
||||||
|
|
||||||
|
inline void setParam2b(bool param) { m_param2b = param; }
|
||||||
|
inline bool getParam2b() const { return m_param2b; }
|
||||||
|
|
||||||
|
inline void setParam3b(bool param) { m_param3b = param; }
|
||||||
|
inline bool getParam3b() const { return m_param3b; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CParams() {
|
||||||
|
m_isUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static CParams* instance_;
|
||||||
|
|
||||||
|
// weather update;
|
||||||
|
bool m_isUpdate;
|
||||||
|
|
||||||
|
//! float params
|
||||||
|
float m_param1f;
|
||||||
|
float m_param2f;
|
||||||
|
float m_param3f;
|
||||||
|
|
||||||
|
//! int params
|
||||||
|
int m_param1i;
|
||||||
|
int m_param2i;
|
||||||
|
int m_param3i;
|
||||||
|
|
||||||
|
//! bool params
|
||||||
|
bool m_param1b;
|
||||||
|
bool m_param2b;
|
||||||
|
bool m_param3b;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PARAMS_H_
|
@ -0,0 +1,194 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: plate Header
|
||||||
|
// Version: 1.0
|
||||||
|
// Date: 2015-03-12
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Desciption:
|
||||||
|
// An abstract class for car plate.
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_PLATE_H_
|
||||||
|
#define EASYPR_CORE_PLATE_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "easypr/core/character.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CPlate {
|
||||||
|
public:
|
||||||
|
CPlate() {
|
||||||
|
m_score = -1;
|
||||||
|
m_plateStr = "";
|
||||||
|
m_plateColor = UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPlate(const CPlate& other) {
|
||||||
|
m_plateMat = other.m_plateMat;
|
||||||
|
m_chineseMat = other.m_chineseMat;
|
||||||
|
m_chineseKey = other.m_chineseKey;
|
||||||
|
m_score = other.m_score;
|
||||||
|
m_platePos = other.m_platePos;
|
||||||
|
m_plateStr = other.m_plateStr;
|
||||||
|
m_locateType = other.m_locateType;
|
||||||
|
m_plateColor = other.m_plateColor;
|
||||||
|
m_line = other.m_line;
|
||||||
|
m_leftPoint = other.m_leftPoint;
|
||||||
|
m_rightPoint = other.m_rightPoint;
|
||||||
|
m_mergeCharRect = other.m_mergeCharRect;
|
||||||
|
m_maxCharRect = other.m_maxCharRect;
|
||||||
|
m_scale = other.m_scale;
|
||||||
|
m_distVec = other.m_distVec;
|
||||||
|
|
||||||
|
m_mserCharVec = other.m_mserCharVec;
|
||||||
|
m_reutCharVec = other.m_reutCharVec;
|
||||||
|
m_ostuLevel = other.m_ostuLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPlate& operator=(const CPlate& other) {
|
||||||
|
if (this != &other) {
|
||||||
|
m_plateMat = other.m_plateMat;
|
||||||
|
m_chineseMat = other.m_chineseMat;
|
||||||
|
m_chineseKey = other.m_chineseKey;
|
||||||
|
m_score = other.m_score;
|
||||||
|
m_platePos = other.m_platePos;
|
||||||
|
m_plateStr = other.m_plateStr;
|
||||||
|
m_locateType = other.m_locateType;
|
||||||
|
m_plateColor = other.m_plateColor;
|
||||||
|
m_line = other.m_line;
|
||||||
|
m_leftPoint = other.m_leftPoint;
|
||||||
|
m_rightPoint = other.m_rightPoint;
|
||||||
|
m_mergeCharRect = other.m_mergeCharRect;
|
||||||
|
m_maxCharRect = other.m_maxCharRect;
|
||||||
|
|
||||||
|
m_distVec = other.m_distVec;
|
||||||
|
|
||||||
|
m_mserCharVec = other.m_mserCharVec;
|
||||||
|
m_reutCharVec = other.m_reutCharVec;
|
||||||
|
m_ostuLevel = other.m_ostuLevel;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setPlateMat(Mat param) { m_plateMat = param; }
|
||||||
|
inline Mat getPlateMat() const { return m_plateMat; }
|
||||||
|
|
||||||
|
inline void setChineseMat(Mat param) { m_chineseMat = param; }
|
||||||
|
inline Mat getChineseMat() const { return m_chineseMat; }
|
||||||
|
|
||||||
|
inline void setChineseKey(String param) { m_chineseKey = param; }
|
||||||
|
inline String getChineseKey() const { return m_chineseKey; }
|
||||||
|
|
||||||
|
inline void setPlatePos(RotatedRect param) { m_platePos = param; }
|
||||||
|
inline RotatedRect getPlatePos() const { return m_platePos; }
|
||||||
|
|
||||||
|
inline void setPlateStr(String param) { m_plateStr = param; }
|
||||||
|
inline String getPlateStr() const { return m_plateStr; }
|
||||||
|
|
||||||
|
inline void setPlateLocateType(LocateType param) { m_locateType = param; }
|
||||||
|
inline LocateType getPlateLocateType() const { return m_locateType; }
|
||||||
|
|
||||||
|
inline void setPlateColor(Color param) { m_plateColor = param; }
|
||||||
|
inline Color getPlateColor() const { return m_plateColor; }
|
||||||
|
|
||||||
|
inline void setPlateScale(float param) { m_scale = param; }
|
||||||
|
inline float getPlateScale() const { return m_scale; }
|
||||||
|
|
||||||
|
inline void setPlateScore(double param) { m_score = param; }
|
||||||
|
inline double getPlateScore() const { return m_score; }
|
||||||
|
|
||||||
|
inline void setPlateLine(Vec4f param) { m_line = param; }
|
||||||
|
inline Vec4f getPlateLine() const { return m_line; }
|
||||||
|
|
||||||
|
inline void setPlateLeftPoint(Point param) { m_leftPoint = param; }
|
||||||
|
inline Point getPlateLeftPoint() const { return m_leftPoint; }
|
||||||
|
|
||||||
|
inline void setPlateRightPoint(Point param) { m_rightPoint = param; }
|
||||||
|
inline Point getPlateRightPoint() const { return m_rightPoint; }
|
||||||
|
|
||||||
|
inline void setPlateMergeCharRect(Rect param) { m_mergeCharRect = param; }
|
||||||
|
inline Rect getPlateMergeCharRect() const { return m_mergeCharRect; }
|
||||||
|
|
||||||
|
inline void setPlateMaxCharRect(Rect param) { m_maxCharRect = param; }
|
||||||
|
inline Rect getPlateMaxCharRect() const { return m_maxCharRect; }
|
||||||
|
|
||||||
|
inline void setPlatDistVec(Vec2i param) { m_distVec = param; }
|
||||||
|
inline Vec2i getPlateDistVec() const { return m_distVec; }
|
||||||
|
|
||||||
|
inline void setOstuLevel(double param) { m_ostuLevel = param; }
|
||||||
|
inline double getOstuLevel() const { return m_ostuLevel; }
|
||||||
|
|
||||||
|
inline void setMserCharacter(const std::vector<CCharacter>& param) { m_mserCharVec = param; }
|
||||||
|
inline void addMserCharacter(CCharacter param) { m_mserCharVec.push_back(param); }
|
||||||
|
inline std::vector<CCharacter> getCopyOfMserCharacters() { return m_mserCharVec; }
|
||||||
|
|
||||||
|
inline void setReutCharacter(const std::vector<CCharacter>& param) { m_reutCharVec = param; }
|
||||||
|
inline void addReutCharacter(CCharacter param) { m_reutCharVec.push_back(param); }
|
||||||
|
inline std::vector<CCharacter> getCopyOfReutCharacters() { return m_reutCharVec; }
|
||||||
|
|
||||||
|
bool operator < (const CPlate& plate) const { return (m_score < plate.m_score); }
|
||||||
|
bool operator < (const CPlate& plate) { return (m_score < plate.m_score); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! plate mat
|
||||||
|
Mat m_plateMat;
|
||||||
|
|
||||||
|
//! plate rect
|
||||||
|
RotatedRect m_platePos;
|
||||||
|
|
||||||
|
//! plate license
|
||||||
|
String m_plateStr;
|
||||||
|
|
||||||
|
//! plate locate type
|
||||||
|
LocateType m_locateType;
|
||||||
|
|
||||||
|
//! plate color type
|
||||||
|
Color m_plateColor;
|
||||||
|
|
||||||
|
//! scale ratio
|
||||||
|
float m_scale;
|
||||||
|
|
||||||
|
//! plate likely
|
||||||
|
double m_score;
|
||||||
|
|
||||||
|
//! avg ostu level
|
||||||
|
double m_ostuLevel;
|
||||||
|
|
||||||
|
//! middle line
|
||||||
|
Vec4f m_line;
|
||||||
|
|
||||||
|
//! left point and right point;
|
||||||
|
Point m_leftPoint;
|
||||||
|
Point m_rightPoint;
|
||||||
|
|
||||||
|
Rect m_mergeCharRect;
|
||||||
|
Rect m_maxCharRect;
|
||||||
|
|
||||||
|
std::vector<CCharacter> m_mserCharVec;
|
||||||
|
std::vector<CCharacter> m_slwdCharVec;
|
||||||
|
|
||||||
|
std::vector<CCharacter> m_ostuCharVec;
|
||||||
|
std::vector<CCharacter> m_reutCharVec;
|
||||||
|
|
||||||
|
int m_charCount;
|
||||||
|
|
||||||
|
//! chinese mat;
|
||||||
|
Mat m_chineseMat;
|
||||||
|
|
||||||
|
//! chinese key;
|
||||||
|
String m_chineseKey;
|
||||||
|
|
||||||
|
//! distVec
|
||||||
|
Vec2i m_distVec;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATE_H_
|
@ -0,0 +1,125 @@
|
|||||||
|
#ifndef EASYPR_CORE_PLATEDETECT_H_
|
||||||
|
#define EASYPR_CORE_PLATEDETECT_H_
|
||||||
|
|
||||||
|
#include "easypr/core/plate_locate.h"
|
||||||
|
#include "easypr/core/plate_judge.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CPlateDetect {
|
||||||
|
public:
|
||||||
|
CPlateDetect();
|
||||||
|
|
||||||
|
~CPlateDetect();
|
||||||
|
|
||||||
|
/** @brief Plate detect in an image.
|
||||||
|
|
||||||
|
The function detects plate in an image. It can use sobel, color, and character method or the combinations of them.
|
||||||
|
|
||||||
|
@param src Source image.
|
||||||
|
@param resultVec Destination vector of CPlate.
|
||||||
|
@param type Detect type. (eg. PR_DETECT_SOBEL + PR_DETECT_COLOR)
|
||||||
|
@param showDetectArea
|
||||||
|
@param index
|
||||||
|
*/
|
||||||
|
int plateDetect(Mat src, std::vector<CPlate> &resultVec, int type,
|
||||||
|
bool showDetectArea, int img_index = 0);
|
||||||
|
|
||||||
|
|
||||||
|
/** @brief Plate detect in an image.
|
||||||
|
|
||||||
|
The function detects plate in an image. It can use sobel, color, and character method or the combinations of them.
|
||||||
|
Use default m_type, it can use setDetectType() to set it;
|
||||||
|
|
||||||
|
@param src Source image.
|
||||||
|
@param resultVec Destination vector of CPlate.
|
||||||
|
@param index
|
||||||
|
*/
|
||||||
|
int plateDetect(Mat src, std::vector<CPlate> &resultVec, int img_index = 0);
|
||||||
|
|
||||||
|
void LoadSVM(std::string s);
|
||||||
|
|
||||||
|
inline void setPDLifemode(bool param) { m_plateLocate->setLifemode(param); }
|
||||||
|
|
||||||
|
inline void setPDDebug(bool param) {
|
||||||
|
m_plateLocate->setDebug(param);
|
||||||
|
setDetectShow(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool getPDDebug() { return m_plateLocate->getDebug(); }
|
||||||
|
|
||||||
|
inline void setDetectType(int param) { m_type = param; }
|
||||||
|
|
||||||
|
inline void setGaussianBlurSize(int param) {
|
||||||
|
m_plateLocate->setGaussianBlurSize(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getGaussianBlurSize() const {
|
||||||
|
return m_plateLocate->getGaussianBlurSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setMorphSizeWidth(int param) {
|
||||||
|
m_plateLocate->setMorphSizeWidth(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getMorphSizeWidth() const {
|
||||||
|
return m_plateLocate->getMorphSizeWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setMorphSizeHeight(int param) {
|
||||||
|
m_plateLocate->setMorphSizeHeight(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int getMorphSizeHeight() const {
|
||||||
|
return m_plateLocate->getMorphSizeHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setVerifyError(float param) {
|
||||||
|
m_plateLocate->setVerifyError(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float getVerifyError() const {
|
||||||
|
return m_plateLocate->getVerifyError();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setVerifyAspect(float param) {
|
||||||
|
m_plateLocate->setVerifyAspect(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float getVerifyAspect() const {
|
||||||
|
return m_plateLocate->getVerifyAspect();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setVerifyMin(int param) { m_plateLocate->setVerifyMin(param); }
|
||||||
|
|
||||||
|
inline void setVerifyMax(int param) { m_plateLocate->setVerifyMax(param); }
|
||||||
|
|
||||||
|
inline void setJudgeAngle(int param) { m_plateLocate->setJudgeAngle(param); }
|
||||||
|
|
||||||
|
inline void setMaxPlates(int param) { m_maxPlates = param; }
|
||||||
|
|
||||||
|
inline int getMaxPlates() const { return m_maxPlates; }
|
||||||
|
|
||||||
|
inline void setDetectShow(bool param) { m_showDetect = param; }
|
||||||
|
inline bool getDetectShow() const { return m_showDetect; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_maxPlates;
|
||||||
|
|
||||||
|
//SceneMode m_mode;
|
||||||
|
|
||||||
|
CPlateLocate* m_plateLocate;
|
||||||
|
|
||||||
|
int m_type;
|
||||||
|
|
||||||
|
static std::string m_pathSvm;
|
||||||
|
|
||||||
|
// show the detect result image
|
||||||
|
bool m_showDetect;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATEDETECT_H_
|
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef EASYPR_CORE_PLATEJUDGE_H_
|
||||||
|
#define EASYPR_CORE_PLATEJUDGE_H_
|
||||||
|
|
||||||
|
#include "easypr/core/plate.hpp"
|
||||||
|
#include "easypr/core/feature.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class PlateJudge {
|
||||||
|
public:
|
||||||
|
static PlateJudge* instance();
|
||||||
|
void LoadModel(std::string path);
|
||||||
|
|
||||||
|
int plateJudgeUsingNMS(const std::vector<CPlate>&, std::vector<CPlate>&, int maxPlates = 5);
|
||||||
|
int plateSetScore(CPlate& plate);
|
||||||
|
|
||||||
|
int plateJudge(const Mat& plateMat);
|
||||||
|
int plateJudge(const std::vector<Mat> &inVec,
|
||||||
|
std::vector<Mat> &resultVec);
|
||||||
|
int plateJudge(const std::vector<CPlate> &inVec,
|
||||||
|
std::vector<CPlate> &resultVec);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// singleton
|
||||||
|
PlateJudge();
|
||||||
|
|
||||||
|
static PlateJudge* instance_;
|
||||||
|
|
||||||
|
svmCallback extractFeature;
|
||||||
|
|
||||||
|
cv::Ptr<ml::SVM> svm_;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATEJUDGE_H_
|
@ -0,0 +1,141 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: plate_locate Header
|
||||||
|
// Version: 1.2
|
||||||
|
// Date: 2014-09-19
|
||||||
|
// MDate: 2014-09-29
|
||||||
|
// MDate: 2015-03-13
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Reference: Mastering OpenCV with Practical Computer Vision Projects
|
||||||
|
// Reference: CSDN Bloger taotao1233
|
||||||
|
// Desciption:
|
||||||
|
// Defines CPlateLocate
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_PLATELOCATE_H_
|
||||||
|
#define EASYPR_CORE_PLATELOCATE_H_
|
||||||
|
|
||||||
|
#include "easypr/core/plate.hpp"
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CPlateLocate {
|
||||||
|
public:
|
||||||
|
CPlateLocate();
|
||||||
|
|
||||||
|
int sobelFrtSearch(const Mat& src, std::vector<Rect_<float>>& outRects);
|
||||||
|
int sobelSecSearch(Mat& bound, Point2f refpoint,
|
||||||
|
std::vector<RotatedRect>& outRects);
|
||||||
|
int sobelSecSearchPart(Mat& bound, Point2f refpoint,
|
||||||
|
std::vector<RotatedRect>& outRects);
|
||||||
|
|
||||||
|
int deskew(const Mat& src, const Mat& src_b,
|
||||||
|
std::vector<RotatedRect>& inRects, std::vector<CPlate>& outPlates,
|
||||||
|
bool useDeteleArea = true, Color color = UNKNOWN);
|
||||||
|
|
||||||
|
bool isdeflection(const Mat& in, const double angle, double& slope);
|
||||||
|
|
||||||
|
int sobelOper(const Mat& in, Mat& out, int blurSize, int morphW, int morphH);
|
||||||
|
|
||||||
|
|
||||||
|
bool rotation(Mat& in, Mat& out, const Size rect_size, const Point2f center,
|
||||||
|
const double angle);
|
||||||
|
|
||||||
|
void affine(const Mat& in, Mat& out, const double slope);
|
||||||
|
|
||||||
|
int plateColorLocate(Mat src, std::vector<CPlate>& candPlates, int index = 0);
|
||||||
|
int plateSobelLocate(Mat src, std::vector<CPlate>& candPlates, int index = 0);
|
||||||
|
int sobelOperT(const Mat& in, Mat& out, int blurSize, int morphW, int morphH);
|
||||||
|
|
||||||
|
int plateMserLocate(Mat src, std::vector<CPlate>& candPlates, int index = 0);
|
||||||
|
|
||||||
|
|
||||||
|
int colorSearch(const Mat& src, const Color r, Mat& out,
|
||||||
|
std::vector<RotatedRect>& outRects);
|
||||||
|
|
||||||
|
int mserSearch(const Mat &src, vector<Mat>& out,
|
||||||
|
vector<vector<CPlate>>& out_plateVec, bool usePlateMser, vector<vector<RotatedRect>>& out_plateRRect,
|
||||||
|
int img_index = 0, bool showDebug = false);
|
||||||
|
|
||||||
|
int plateLocate(Mat, std::vector<Mat>&, int = 0);
|
||||||
|
int plateLocate(Mat, std::vector<CPlate>&, int = 0);
|
||||||
|
|
||||||
|
bool verifySizes(RotatedRect mr);
|
||||||
|
|
||||||
|
void setLifemode(bool param);
|
||||||
|
|
||||||
|
inline void setGaussianBlurSize(int param) { m_GaussianBlurSize = param; }
|
||||||
|
inline int getGaussianBlurSize() const { return m_GaussianBlurSize; }
|
||||||
|
|
||||||
|
inline void setMorphSizeWidth(int param) { m_MorphSizeWidth = param; }
|
||||||
|
inline int getMorphSizeWidth() const { return m_MorphSizeWidth; }
|
||||||
|
|
||||||
|
inline void setMorphSizeHeight(int param) { m_MorphSizeHeight = param; }
|
||||||
|
inline int getMorphSizeHeight() const { return m_MorphSizeHeight; }
|
||||||
|
|
||||||
|
inline void setVerifyError(float param) { m_error = param; }
|
||||||
|
inline float getVerifyError() const { return m_error; }
|
||||||
|
inline void setVerifyAspect(float param) { m_aspect = param; }
|
||||||
|
inline float getVerifyAspect() const { return m_aspect; }
|
||||||
|
|
||||||
|
inline void setVerifyMin(int param) { m_verifyMin = param; }
|
||||||
|
inline void setVerifyMax(int param) { m_verifyMax = param; }
|
||||||
|
|
||||||
|
inline void setJudgeAngle(int param) { m_angle = param; }
|
||||||
|
|
||||||
|
inline void setDebug(bool param) { m_debug = param; }
|
||||||
|
|
||||||
|
|
||||||
|
inline bool getDebug() { return m_debug; }
|
||||||
|
|
||||||
|
|
||||||
|
static const int DEFAULT_GAUSSIANBLUR_SIZE = 5;
|
||||||
|
static const int SOBEL_SCALE = 1;
|
||||||
|
static const int SOBEL_DELTA = 0;
|
||||||
|
static const int SOBEL_DDEPTH = CV_16S;
|
||||||
|
static const int SOBEL_X_WEIGHT = 1;
|
||||||
|
static const int SOBEL_Y_WEIGHT = 0;
|
||||||
|
static const int DEFAULT_MORPH_SIZE_WIDTH = 17; // 17
|
||||||
|
static const int DEFAULT_MORPH_SIZE_HEIGHT = 3; // 3
|
||||||
|
|
||||||
|
|
||||||
|
static const int WIDTH = 136;
|
||||||
|
static const int HEIGHT = 36;
|
||||||
|
static const int TYPE = CV_8UC3;
|
||||||
|
|
||||||
|
|
||||||
|
static const int DEFAULT_VERIFY_MIN = 1; // 3
|
||||||
|
static const int DEFAULT_VERIFY_MAX = 24; // 20
|
||||||
|
|
||||||
|
static const int DEFAULT_ANGLE = 60; // 30
|
||||||
|
|
||||||
|
|
||||||
|
static const int DEFAULT_DEBUG = 1;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
int m_GaussianBlurSize;
|
||||||
|
|
||||||
|
int m_MorphSizeWidth;
|
||||||
|
int m_MorphSizeHeight;
|
||||||
|
|
||||||
|
|
||||||
|
float m_error;
|
||||||
|
float m_aspect;
|
||||||
|
int m_verifyMin;
|
||||||
|
int m_verifyMax;
|
||||||
|
|
||||||
|
int m_angle;
|
||||||
|
|
||||||
|
|
||||||
|
bool m_debug;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATELOCATE_H_
|
@ -0,0 +1,54 @@
|
|||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: plate_recognize Header
|
||||||
|
// Version: 1.0
|
||||||
|
// Date: 2014-09-28
|
||||||
|
// Author: liuruoze
|
||||||
|
// Copyright: liuruoze
|
||||||
|
// Reference: Mastering OpenCV with Practical Computer Vision Projects
|
||||||
|
// Reference: CSDN Bloger taotao1233
|
||||||
|
// Desciption:
|
||||||
|
// Defines CPlateRecognize
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef EASYPR_CORE_PLATERECOGNIZE_H_
|
||||||
|
#define EASYPR_CORE_PLATERECOGNIZE_H_
|
||||||
|
|
||||||
|
#include "easypr/core/plate_detect.h"
|
||||||
|
#include "easypr/core/chars_recognise.h"
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class CPlateRecognize : public CPlateDetect, public CCharsRecognise {
|
||||||
|
public:
|
||||||
|
CPlateRecognize();
|
||||||
|
|
||||||
|
int plateRecognize(const Mat& src, std::vector<CPlate> &plateVec, int img_index = 0);
|
||||||
|
int plateRecognize(const Mat& src, std::vector<std::string> &licenseVec);
|
||||||
|
|
||||||
|
inline void setLifemode(bool param) { CPlateDetect::setPDLifemode(param); }
|
||||||
|
inline void setDetectType(int param) { CPlateDetect::setDetectType(param); }
|
||||||
|
|
||||||
|
inline void setResultShow(bool param) { m_showResult = param; }
|
||||||
|
inline bool getResultShow() const { return m_showResult; }
|
||||||
|
inline void setDetectShow(bool param) { CPlateDetect::setDetectShow(param); }
|
||||||
|
inline void setDebug(bool param) { setResultShow(param); }
|
||||||
|
|
||||||
|
void LoadSVM(std::string path);
|
||||||
|
void LoadANN(std::string path);
|
||||||
|
void LoadChineseANN(std::string path);
|
||||||
|
|
||||||
|
//v1.6 added
|
||||||
|
void LoadGrayChANN(std::string path);
|
||||||
|
void LoadChineseMapping(std::string path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// show the detect and recognition result image
|
||||||
|
bool m_showResult;
|
||||||
|
DISABLE_ASSIGN_AND_COPY(CPlateRecognize);
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* \namespace easypr */
|
||||||
|
|
||||||
|
#endif // EASYPR_CORE_PLATERECOGNIZE_H_
|
@ -0,0 +1,43 @@
|
|||||||
|
#ifndef EASYPR_TRAIN_ANNCHTRAIN_H_
|
||||||
|
#define EASYPR_TRAIN_ANNCHTRAIN_H_
|
||||||
|
|
||||||
|
#include "easypr/train/train.h"
|
||||||
|
#include "easypr/util/kv.h"
|
||||||
|
#include "easypr/core/feature.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class AnnChTrain : public ITrain {
|
||||||
|
public:
|
||||||
|
explicit AnnChTrain(const char* chars_folder, const char* xml);
|
||||||
|
|
||||||
|
virtual void train();
|
||||||
|
|
||||||
|
virtual void test();
|
||||||
|
|
||||||
|
std::pair<std::string, std::string> identifyGrayChinese(cv::Mat input);
|
||||||
|
|
||||||
|
inline void setNumberForCount(int n) {
|
||||||
|
m_number_for_count = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual cv::Ptr<cv::ml::TrainData> tdata();
|
||||||
|
|
||||||
|
void trainVal(size_t number_for_count = 100);
|
||||||
|
|
||||||
|
cv::Ptr<cv::ml::ANN_MLP> ann_;
|
||||||
|
const char* ann_xml_;
|
||||||
|
const char* chars_folder_;
|
||||||
|
|
||||||
|
std::shared_ptr<Kv> kv_;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
int m_number_for_count;
|
||||||
|
|
||||||
|
annCallback extractFeature;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_TRAIN_ANNCHTRAIN_H_
|
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef EASYPR_TRAIN_ANNTRAIN_H_
|
||||||
|
#define EASYPR_TRAIN_ANNTRAIN_H_
|
||||||
|
|
||||||
|
#include "easypr/train/train.h"
|
||||||
|
#include "easypr/util/kv.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class AnnTrain : public ITrain {
|
||||||
|
public:
|
||||||
|
explicit AnnTrain(const char* chars_folder, const char* xml);
|
||||||
|
|
||||||
|
virtual void train();
|
||||||
|
|
||||||
|
virtual void test();
|
||||||
|
|
||||||
|
std::pair<std::string, std::string> identifyChinese(cv::Mat input);
|
||||||
|
std::pair<std::string, std::string> identify(cv::Mat input);
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual cv::Ptr<cv::ml::TrainData> tdata();
|
||||||
|
|
||||||
|
cv::Ptr<cv::ml::TrainData> sdata(size_t number_for_count = 100);
|
||||||
|
|
||||||
|
cv::Ptr<cv::ml::ANN_MLP> ann_;
|
||||||
|
const char* ann_xml_;
|
||||||
|
const char* chars_folder_;
|
||||||
|
|
||||||
|
std::shared_ptr<Kv> kv_;
|
||||||
|
int type;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_TRAIN_ANNTRAIN_H_
|
@ -0,0 +1,27 @@
|
|||||||
|
#ifndef EASYPR_CREATE_DATA_H_
|
||||||
|
#define EASYPR_CREATE_DATA_H_
|
||||||
|
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "easypr/config.h"
|
||||||
|
|
||||||
|
using namespace cv;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/*! \namespace easypr
|
||||||
|
Namespace where all the C++ EasyPR functionality resides
|
||||||
|
*/
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
// shift an image
|
||||||
|
Mat translateImg(Mat img, int offsetx, int offsety, int bk = 0);
|
||||||
|
// rotate an image
|
||||||
|
Mat rotateImg(Mat source, float angle, int bk = 0);
|
||||||
|
|
||||||
|
// crop the image
|
||||||
|
Mat cropImg(Mat src, int x, int y, int shift, int bk = 0);
|
||||||
|
|
||||||
|
Mat generateSyntheticImage(const Mat& image, int use_swap = 1);
|
||||||
|
|
||||||
|
} /*! \namespace easypr*/
|
||||||
|
|
||||||
|
#endif // EASYPR_CREATE_DATA_H_
|
@ -0,0 +1,42 @@
|
|||||||
|
#ifndef EASYPR_TRAIN_SVMTRAIN_H_
|
||||||
|
#define EASYPR_TRAIN_SVMTRAIN_H_
|
||||||
|
|
||||||
|
#include "easypr/train/train.h"
|
||||||
|
#include <vector>
|
||||||
|
#include "easypr/config.h"
|
||||||
|
#include "easypr/core/feature.h"
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
//int svmTrain(bool dividePrepared, bool trainPrepared);
|
||||||
|
|
||||||
|
class SvmTrain : public ITrain {
|
||||||
|
public:
|
||||||
|
typedef struct {
|
||||||
|
std::string file;
|
||||||
|
SvmLabel label;
|
||||||
|
} TrainItem;
|
||||||
|
|
||||||
|
SvmTrain(const char* plates_folder, const char* xml);
|
||||||
|
|
||||||
|
virtual void train();
|
||||||
|
|
||||||
|
virtual void test();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void prepare();
|
||||||
|
|
||||||
|
virtual cv::Ptr<cv::ml::TrainData> tdata();
|
||||||
|
|
||||||
|
cv::Ptr<cv::ml::SVM> svm_;
|
||||||
|
const char* plates_folder_;
|
||||||
|
const char* svm_xml_;
|
||||||
|
std::vector<TrainItem> train_file_list_;
|
||||||
|
std::vector<TrainItem> test_file_list_;
|
||||||
|
|
||||||
|
svmCallback extractFeature;
|
||||||
|
bool isPrepared = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_TRAIN_SVMTRAIN_H_
|
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef EASYPR_TRAIN_TRAIN_H_
|
||||||
|
#define EASYPR_TRAIN_TRAIN_H_
|
||||||
|
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class ITrain {
|
||||||
|
public:
|
||||||
|
ITrain();
|
||||||
|
|
||||||
|
virtual ~ITrain();
|
||||||
|
|
||||||
|
virtual void train() = 0;
|
||||||
|
|
||||||
|
virtual void test() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual cv::Ptr<cv::ml::TrainData> tdata() = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_TRAIN_TRAIN_H_
|
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef EASYPR_UTIL_KV_H_
|
||||||
|
#define EASYPR_UTIL_KV_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
|
||||||
|
class Kv {
|
||||||
|
public:
|
||||||
|
Kv();
|
||||||
|
|
||||||
|
void load(const std::string &file);
|
||||||
|
|
||||||
|
std::string get(const std::string &key);
|
||||||
|
|
||||||
|
void add(const std::string &key, const std::string &value);
|
||||||
|
|
||||||
|
void remove(const std::string &key);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::string> data_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EASYPR_UTIL_KV_H_
|
@ -0,0 +1,356 @@
|
|||||||
|
/***********************
|
||||||
|
* This file is a packed library of
|
||||||
|
* ProgramOptions(http://github.com/Micooz/ProgramOptions).
|
||||||
|
* ProgramOptions is a library for generating and parsing command line.
|
||||||
|
***********************/
|
||||||
|
|
||||||
|
#ifndef UTIL_PROGRAM_OPTIONS_H
|
||||||
|
#define UTIL_PROGRAM_OPTIONS_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <initializer_list>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define DEPRECATED(func) func __attribute__((deprecated))
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define DEPRECATED(func) __declspec(deprecated) func
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace program_options {
|
||||||
|
|
||||||
|
class Row {
|
||||||
|
public:
|
||||||
|
Row();
|
||||||
|
|
||||||
|
enum Field { kShort, kLong, kDefault, kDescription };
|
||||||
|
|
||||||
|
typedef std::initializer_list<Field> Order;
|
||||||
|
|
||||||
|
// getter
|
||||||
|
|
||||||
|
inline std::string oshort() const { return option_short; }
|
||||||
|
|
||||||
|
inline std::string olong() const { return option_long; }
|
||||||
|
|
||||||
|
inline std::string value() const { return default_value; }
|
||||||
|
|
||||||
|
inline std::string desc() const { return description; }
|
||||||
|
|
||||||
|
inline bool required() const { return require_value; }
|
||||||
|
|
||||||
|
// setter
|
||||||
|
|
||||||
|
inline void oshort(const std::string& oshort) { option_short = oshort; }
|
||||||
|
|
||||||
|
inline void olong(const std::string& olong) { option_long = olong; }
|
||||||
|
|
||||||
|
inline void value(const std::string& value) { default_value = value; }
|
||||||
|
|
||||||
|
inline void desc(const std::string& desc) { description = desc; }
|
||||||
|
|
||||||
|
inline void required(bool required) { require_value = required; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool require_value;
|
||||||
|
std::string option_short;
|
||||||
|
std::string option_long;
|
||||||
|
std::string default_value;
|
||||||
|
std::string description;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Subroutine {
|
||||||
|
public:
|
||||||
|
typedef std::vector<Row> Usages;
|
||||||
|
typedef std::initializer_list<const char*> TemplateValue;
|
||||||
|
typedef std::vector<TemplateValue> TemplateValues;
|
||||||
|
|
||||||
|
Subroutine();
|
||||||
|
|
||||||
|
Subroutine(const char* name, const char* description);
|
||||||
|
|
||||||
|
inline void add_usage_line(const Row& row) { usages_.push_back(row); }
|
||||||
|
|
||||||
|
inline void add_usage_line(const TemplateValue& row) {
|
||||||
|
templates_.push_back(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void set_first_line(const char* line) { first_line_ = line; }
|
||||||
|
|
||||||
|
inline void set_description(const char* desc) { description_ = desc; }
|
||||||
|
|
||||||
|
inline void set_template(const char* tstr, const Row::Order& order) {
|
||||||
|
template_str_ = tstr;
|
||||||
|
order_ = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters
|
||||||
|
|
||||||
|
inline std::string to_string() {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << *this;
|
||||||
|
return std::move(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string get_name() const { return name_; }
|
||||||
|
|
||||||
|
inline const char* get_description() const { return description_; }
|
||||||
|
|
||||||
|
inline const char* get_first_line() const { return first_line_; }
|
||||||
|
|
||||||
|
inline Usages::iterator begin() { return usages_.begin(); }
|
||||||
|
|
||||||
|
inline Usages::iterator end() { return usages_.end(); }
|
||||||
|
|
||||||
|
inline size_t size() { return usages_.size(); }
|
||||||
|
|
||||||
|
inline Row& at(size_t i) { return usages_.at(i); }
|
||||||
|
|
||||||
|
inline const Usages& get_usage() const { return usages_; }
|
||||||
|
|
||||||
|
inline static const char* get_default_name() { return "EmptySubroutine"; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, Subroutine& subroutine);
|
||||||
|
|
||||||
|
void print_with_row(std::ostream& out);
|
||||||
|
|
||||||
|
void print_with_template(std::ostream& out);
|
||||||
|
|
||||||
|
Usages usages_;
|
||||||
|
TemplateValues templates_;
|
||||||
|
const char* first_line_;
|
||||||
|
const char* description_;
|
||||||
|
std::string name_;
|
||||||
|
std::string template_str_;
|
||||||
|
Row::Order order_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Parser;
|
||||||
|
|
||||||
|
class Generator {
|
||||||
|
public:
|
||||||
|
typedef std::map<std::string, Subroutine*> SubroutineCollection;
|
||||||
|
|
||||||
|
Generator();
|
||||||
|
|
||||||
|
~Generator();
|
||||||
|
|
||||||
|
// begin a new usage generate process and
|
||||||
|
// create the first line that you will see in the result.
|
||||||
|
// if you don't want to create the first line,
|
||||||
|
// it's ok to create your usage lines without calling make_usage() first.
|
||||||
|
Generator& make_usage(const char* first_line);
|
||||||
|
|
||||||
|
Parser* make_parser();
|
||||||
|
|
||||||
|
// generate usage lines for a subroutine.
|
||||||
|
Generator& add_subroutine(const char* name);
|
||||||
|
|
||||||
|
Generator& add_subroutine(const char* name, const char* description);
|
||||||
|
|
||||||
|
// get pairs of subroutine name and its description.
|
||||||
|
std::map<std::string, std::string> get_subroutine_list();
|
||||||
|
|
||||||
|
// generate and return the result as std::string
|
||||||
|
inline std::string to_string() {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << *this;
|
||||||
|
return std::move(ss.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// add an usage line, it doesn't require a value
|
||||||
|
inline Generator& operator()(const char* option, const char* description) {
|
||||||
|
this->add_usage_line(option, "", description);
|
||||||
|
(get_subroutine()->end() - 1)->required(false);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add an usage line, it requires a value(may has a default value)
|
||||||
|
inline Generator& operator()(const char* option, const char* default_value,
|
||||||
|
const char* description) {
|
||||||
|
this->add_usage_line(option, default_value, description);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this method is for subroutine usage printing.
|
||||||
|
// e.g., cout << generator("subroutine_name");
|
||||||
|
inline Subroutine& operator()(const char* name) {
|
||||||
|
assert(subroutines_.find(name) != subroutines_.end());
|
||||||
|
return *subroutines_.at(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Generator& make_template(const char* template_str,
|
||||||
|
const Row::Order& order) {
|
||||||
|
get_subroutine()->set_template(template_str, order);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline Subroutine* get_subroutine() {
|
||||||
|
return subroutines_.at(current_subroutine_);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& out, Generator& generator);
|
||||||
|
|
||||||
|
// add a usage line.
|
||||||
|
// if delimiter doesn't exist, return false
|
||||||
|
bool add_usage_line(const char* option, const char* default_value,
|
||||||
|
const char* description);
|
||||||
|
|
||||||
|
const char kDelimiter = ',';
|
||||||
|
SubroutineCollection subroutines_;
|
||||||
|
std::string current_subroutine_;
|
||||||
|
Parser* parser_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParseError : public std::exception {
|
||||||
|
public:
|
||||||
|
explicit ParseError(const std::string& msg);
|
||||||
|
|
||||||
|
const char* what() const throw();
|
||||||
|
|
||||||
|
~ParseError() throw();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ParseItem {
|
||||||
|
public:
|
||||||
|
ParseItem(const std::string& value);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dynamic type cast, support base data types including std::string
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
T as() {
|
||||||
|
T r;
|
||||||
|
std::stringstream buf;
|
||||||
|
buf << value_;
|
||||||
|
buf >> r;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* alias of as<std::string>()
|
||||||
|
*/
|
||||||
|
inline std::string val() const { return value_; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get C string directly
|
||||||
|
*/
|
||||||
|
inline const char* c_str() const { return value_.c_str(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string value_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Parser {
|
||||||
|
public:
|
||||||
|
typedef std::vector<std::string> ParameterList;
|
||||||
|
typedef std::map<std::string, ParseItem*> ParseResult;
|
||||||
|
|
||||||
|
Parser();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* release memory allocated in parse()
|
||||||
|
*/
|
||||||
|
~Parser();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* parse the command line by given argc and argv
|
||||||
|
*/
|
||||||
|
ParseResult* parse(const int argc, const char** argv);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* parse the command line by given command string
|
||||||
|
*/
|
||||||
|
ParseResult* parse(const char* command_line);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether a certain option exist
|
||||||
|
*/
|
||||||
|
bool has(const char* key);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether a sequence of options exist
|
||||||
|
* example: has_or(3, "he", "or", "she");
|
||||||
|
*/
|
||||||
|
DEPRECATED(bool has_or(int n, ...)) {
|
||||||
|
va_list keys;
|
||||||
|
va_start(keys, n);
|
||||||
|
while (n--) {
|
||||||
|
const char* key = va_arg(keys, const char*);
|
||||||
|
if (this->has(key)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(keys);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether a sequence of options exist
|
||||||
|
* example: has_and(3, "he", "and", "she");
|
||||||
|
*/
|
||||||
|
DEPRECATED(bool has_and(int n, ...)) {
|
||||||
|
va_list keys;
|
||||||
|
va_start(keys, n);
|
||||||
|
while (n--) {
|
||||||
|
const char* key = va_arg(keys, const char*);
|
||||||
|
if (!this->has(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(keys);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether a sequence of options exist using std::initializer_list
|
||||||
|
* example: has_or({"he", "or", "she"});
|
||||||
|
*/
|
||||||
|
bool has_or(std::initializer_list<const char*> options);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check whether a sequence of options exist using std::initializer_list
|
||||||
|
* example: has_and({"he", "and", "she"});
|
||||||
|
*/
|
||||||
|
bool has_and(std::initializer_list<const char*> options);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the specified option value
|
||||||
|
*/
|
||||||
|
ParseItem* get(const std::string& key);
|
||||||
|
|
||||||
|
inline void set_usage_subroutines(
|
||||||
|
const Generator::SubroutineCollection* subroutines) {
|
||||||
|
subroutines_ = subroutines;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::string get_subroutine_name() const { return subroutine_name_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool init(const int argc, const char** argv);
|
||||||
|
|
||||||
|
void cleanup();
|
||||||
|
|
||||||
|
void set_addition();
|
||||||
|
|
||||||
|
const Generator::SubroutineCollection* subroutines_;
|
||||||
|
std::string subroutine_name_;
|
||||||
|
int argc_;
|
||||||
|
ParameterList args_;
|
||||||
|
ParseResult* pr_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // UTIL_PROGRAM_OPTIONS_H
|
@ -0,0 +1,99 @@
|
|||||||
|
#ifndef PROGRAM_OPTIONS_SWITCH_HPP_
|
||||||
|
#define PROGRAM_OPTIONS_SWITCH_HPP_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
namespace program_options {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The Switch template class.
|
||||||
|
* @param Ty The target type.
|
||||||
|
*/
|
||||||
|
template <typename Ty>
|
||||||
|
class Switch {
|
||||||
|
public:
|
||||||
|
typedef std::function<void(void)> Scope;
|
||||||
|
typedef std::map<const Ty, Scope> Reflections;
|
||||||
|
|
||||||
|
Switch() : has_others_scope_(false) {}
|
||||||
|
|
||||||
|
explicit Switch(const Ty& target)
|
||||||
|
: target_(target), has_others_scope_(false) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a case block with an expression and a callback function.
|
||||||
|
* @param _case The case expression, variable is allowed.
|
||||||
|
* @param callback The callback function, can be a lambda expression.
|
||||||
|
* @return The current Switch instance.
|
||||||
|
*/
|
||||||
|
Switch& found(const Ty& _case, const Scope& callback) {
|
||||||
|
reflections_[_case] = callback;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a default block with a callback function,
|
||||||
|
* if no cases matched, this block will be called.
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
inline void others(const Scope& callback) {
|
||||||
|
has_others_scope_ = true;
|
||||||
|
others_ = callback;
|
||||||
|
this->done();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Finish the cases,
|
||||||
|
* others() will call this method automatically.
|
||||||
|
*/
|
||||||
|
inline void done() {
|
||||||
|
auto kv = reflections_.find(target_);
|
||||||
|
if (kv != reflections_.end()) {
|
||||||
|
// found
|
||||||
|
auto scope = kv->second;
|
||||||
|
scope();
|
||||||
|
} else if (has_others_scope_) {
|
||||||
|
// not found, call others
|
||||||
|
others_();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Combine the cases to this Switch from another Switch.
|
||||||
|
* Note that this two Switch should be the same template.
|
||||||
|
* @param _switch Another Switch instance.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
inline Switch& combine(const Switch& _switch) {
|
||||||
|
for (auto kv : _switch.reflections()) {
|
||||||
|
this->reflections_[kv.first] = kv.second;
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the case-callback pairs.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
inline Reflections reflections() const { return reflections_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
const Ty& target_;
|
||||||
|
bool has_others_scope_;
|
||||||
|
Scope others_;
|
||||||
|
Reflections reflections_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Define which expression does the Switch match.
|
||||||
|
* @param expression
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
template <typename Ty>
|
||||||
|
Switch<Ty> select(const Ty& expression) {
|
||||||
|
return Switch<Ty>(expression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PROGRAM_OPTIONS_SWITCH_HPP_
|
@ -0,0 +1,144 @@
|
|||||||
|
#ifndef EASYPR_UTIL_UTIL_H_
|
||||||
|
#define EASYPR_UTIL_UTIL_H_
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "opencv2/core/core.hpp"
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
|
#define OS_WINDOWS
|
||||||
|
#elif defined(__APPLE__) || defined(APPLE)
|
||||||
|
#define OS_UNIX
|
||||||
|
#elif defined(__linux__) || defined(linux)
|
||||||
|
#define OS_LINUX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SAFE_RELEASE
|
||||||
|
#define SAFE_RELEASE(p) \
|
||||||
|
if ((p)) { \
|
||||||
|
delete (p); \
|
||||||
|
(p) = NULL; \
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace easypr {
|
||||||
|
class Utils {
|
||||||
|
public:
|
||||||
|
static long getTimestamp();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get file name from a given path
|
||||||
|
* bool postfix: including the postfix
|
||||||
|
*/
|
||||||
|
static std::string getFileName(const std::string &path,
|
||||||
|
const bool postfix = false);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Split the given string into segements by a delimiter
|
||||||
|
*/
|
||||||
|
static std::vector<std::string> splitString(const std::string &str,
|
||||||
|
const char delimiter);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the smaller of the two numbers
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
static T min(const T &v1, const T &v2) {
|
||||||
|
return (v1 < v2) ? v1 : v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get files from a given folder
|
||||||
|
* all: including all sub-folders
|
||||||
|
*/
|
||||||
|
static std::vector<std::string> getFiles(const std::string &folder,
|
||||||
|
const bool all = true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print string lines to std::out from an array of const char*,
|
||||||
|
* this function is used for displaying command tips.
|
||||||
|
* lines: should be end with (const char*)NULL.
|
||||||
|
*/
|
||||||
|
static void print_str_lines(const char** lines) {
|
||||||
|
int index = 0;
|
||||||
|
while (lines[index++]) {
|
||||||
|
std::cout << lines[index - 1] << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print string lines using {"string1", "string2"},
|
||||||
|
* this is a easier way benefit from C++11.
|
||||||
|
*/
|
||||||
|
static void print_str_lines(const std::initializer_list<const char*> &lines) {
|
||||||
|
for (auto line : lines) {
|
||||||
|
std::cout << line << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read and print by line.
|
||||||
|
*/
|
||||||
|
static void print_file_lines(const std::string &file) {
|
||||||
|
std::ifstream fs(file);
|
||||||
|
if (fs.good()) {
|
||||||
|
while (!fs.eof()) {
|
||||||
|
std::string line;
|
||||||
|
std::getline(fs, line);
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
line = utf8_to_gbk(line.c_str());
|
||||||
|
#endif
|
||||||
|
std::cout << line << std::endl;
|
||||||
|
}
|
||||||
|
fs.close();
|
||||||
|
} else {
|
||||||
|
std::cerr << "cannot open file: " << file << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
static unsigned int levenshtein_distance(const T &s1, const T &s2) {
|
||||||
|
const size_t len1 = s1.size(), len2 = s2.size();
|
||||||
|
std::vector<unsigned int> col(len2 + 1), prevCol(len2 + 1);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < prevCol.size(); i++) prevCol[i] = i;
|
||||||
|
for (unsigned int i = 0; i < len1; i++) {
|
||||||
|
col[0] = i + 1;
|
||||||
|
for (unsigned int j = 0; j < len2; j++)
|
||||||
|
col[j + 1] = easypr::Utils::min(
|
||||||
|
easypr::Utils::min(prevCol[1 + j] + 1, col[j] + 1),
|
||||||
|
prevCol[j] + (s1[i] == s2[j] ? 0 : 1));
|
||||||
|
col.swap(prevCol);
|
||||||
|
}
|
||||||
|
return prevCol[len2];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create multi-level directories by given folder.
|
||||||
|
*/
|
||||||
|
static bool mkdir(const std::string folder);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure the destination folder exists,
|
||||||
|
* if not, create it, then call cv::imwrite.
|
||||||
|
*/
|
||||||
|
static bool imwrite(const std::string &file, const cv::Mat &image);
|
||||||
|
|
||||||
|
#ifdef OS_WINDOWS
|
||||||
|
static std::string utf8_to_gbk(const char* utf8);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*
|
||||||
|
* Get the last slash from a path, compatible with Windows and *unix.
|
||||||
|
*/
|
||||||
|
static std::size_t get_last_slash(const std::string &path);
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Utils utils;
|
||||||
|
|
||||||
|
} // namespace easypr
|
||||||
|
|
||||||
|
#endif // EASYPR_UTIL_UTIL_H_
|
@ -0,0 +1,24 @@
|
|||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
|
||||||
|
#define CV_VERSION_ID CVAUX_STR(CV_MAJOR_VERSION) CVAUX_STR(CV_MINOR_VERSION) CVAUX_STR(CV_SUBMINOR_VERSION)
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define cvLIB(name) "opencv_" name CV_VERSION_ID "d"
|
||||||
|
#else
|
||||||
|
#define cvLIB(name) "opencv_" name CV_VERSION_ID
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#pragma comment( lib, cvLIB("core") )
|
||||||
|
#pragma comment( lib, cvLIB("imgproc") )
|
||||||
|
#pragma comment( lib, cvLIB("highgui") )
|
||||||
|
#pragma comment( lib, cvLIB("flann") )
|
||||||
|
#pragma comment( lib, cvLIB("features2d") )
|
||||||
|
#pragma comment( lib, cvLIB("calib3d") )
|
||||||
|
#pragma comment( lib, cvLIB("gpu") )
|
||||||
|
#pragma comment( lib, cvLIB("legacy") )
|
||||||
|
#pragma comment( lib, cvLIB("ml") )
|
||||||
|
#pragma comment( lib, cvLIB("objdetect") )
|
||||||
|
#pragma comment( lib, cvLIB("ts") )
|
||||||
|
#pragma comment( lib, cvLIB("video") )
|
||||||
|
#pragma comment( lib, cvLIB("contrib") )
|
||||||
|
#pragma comment( lib, cvLIB("nonfree") )
|
@ -0,0 +1,31 @@
|
|||||||
|
zh_cuan 川
|
||||||
|
zh_gan1 甘
|
||||||
|
zh_hei 黑
|
||||||
|
zh_jin 津
|
||||||
|
zh_liao 辽
|
||||||
|
zh_min 闽
|
||||||
|
zh_qiong 琼
|
||||||
|
zh_sx 晋
|
||||||
|
zh_xin 新
|
||||||
|
zh_yue 粤
|
||||||
|
zh_zhe 浙
|
||||||
|
zh_e 鄂
|
||||||
|
zh_gui 贵
|
||||||
|
zh_hu 沪
|
||||||
|
zh_jing 京
|
||||||
|
zh_lu 鲁
|
||||||
|
zh_ning 宁
|
||||||
|
zh_shan 陕
|
||||||
|
zh_wan 皖
|
||||||
|
zh_yu 豫
|
||||||
|
zh_yun 云
|
||||||
|
zh_gan 赣
|
||||||
|
zh_gui1 桂
|
||||||
|
zh_ji 冀
|
||||||
|
zh_jl 吉
|
||||||
|
zh_meng 蒙
|
||||||
|
zh_qing 青
|
||||||
|
zh_su 苏
|
||||||
|
zh_xiang 湘
|
||||||
|
zh_yu1 渝
|
||||||
|
zh_zang 藏
|
@ -0,0 +1,48 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifdef __OPENCV_BUILD
|
||||||
|
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "opencv2/calib3d.hpp"
|
@ -0,0 +1,150 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CALIB3D_C_H
|
||||||
|
#define OPENCV_CALIB3D_C_H
|
||||||
|
|
||||||
|
#include "opencv2/core/types_c.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Calculates fundamental matrix given a set of corresponding points */
|
||||||
|
#define CV_FM_7POINT 1
|
||||||
|
#define CV_FM_8POINT 2
|
||||||
|
|
||||||
|
#define CV_LMEDS 4
|
||||||
|
#define CV_RANSAC 8
|
||||||
|
|
||||||
|
#define CV_FM_LMEDS_ONLY CV_LMEDS
|
||||||
|
#define CV_FM_RANSAC_ONLY CV_RANSAC
|
||||||
|
#define CV_FM_LMEDS CV_LMEDS
|
||||||
|
#define CV_FM_RANSAC CV_RANSAC
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
CV_ITERATIVE = 0,
|
||||||
|
CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||||
|
CV_P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||||
|
CV_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP"
|
||||||
|
};
|
||||||
|
|
||||||
|
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
|
||||||
|
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
|
||||||
|
#define CV_CALIB_CB_FILTER_QUADS 4
|
||||||
|
#define CV_CALIB_CB_FAST_CHECK 8
|
||||||
|
|
||||||
|
#define CV_CALIB_USE_INTRINSIC_GUESS 1
|
||||||
|
#define CV_CALIB_FIX_ASPECT_RATIO 2
|
||||||
|
#define CV_CALIB_FIX_PRINCIPAL_POINT 4
|
||||||
|
#define CV_CALIB_ZERO_TANGENT_DIST 8
|
||||||
|
#define CV_CALIB_FIX_FOCAL_LENGTH 16
|
||||||
|
#define CV_CALIB_FIX_K1 32
|
||||||
|
#define CV_CALIB_FIX_K2 64
|
||||||
|
#define CV_CALIB_FIX_K3 128
|
||||||
|
#define CV_CALIB_FIX_K4 2048
|
||||||
|
#define CV_CALIB_FIX_K5 4096
|
||||||
|
#define CV_CALIB_FIX_K6 8192
|
||||||
|
#define CV_CALIB_RATIONAL_MODEL 16384
|
||||||
|
#define CV_CALIB_THIN_PRISM_MODEL 32768
|
||||||
|
#define CV_CALIB_FIX_S1_S2_S3_S4 65536
|
||||||
|
#define CV_CALIB_TILTED_MODEL 262144
|
||||||
|
#define CV_CALIB_FIX_TAUX_TAUY 524288
|
||||||
|
#define CV_CALIB_FIX_TANGENT_DIST 2097152
|
||||||
|
|
||||||
|
#define CV_CALIB_NINTRINSIC 18
|
||||||
|
|
||||||
|
#define CV_CALIB_FIX_INTRINSIC 256
|
||||||
|
#define CV_CALIB_SAME_FOCAL_LENGTH 512
|
||||||
|
|
||||||
|
#define CV_CALIB_ZERO_DISPARITY 1024
|
||||||
|
|
||||||
|
/* stereo correspondence parameters and functions */
|
||||||
|
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
|
||||||
|
#define CV_STEREO_BM_XSOBEL 1
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
class CV_EXPORTS CvLevMarq
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CvLevMarq();
|
||||||
|
CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
|
||||||
|
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||||
|
bool completeSymmFlag=false );
|
||||||
|
~CvLevMarq();
|
||||||
|
void init( int nparams, int nerrs, CvTermCriteria criteria=
|
||||||
|
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||||
|
bool completeSymmFlag=false );
|
||||||
|
bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
|
||||||
|
bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
void step();
|
||||||
|
enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
|
||||||
|
|
||||||
|
cv::Ptr<CvMat> mask;
|
||||||
|
cv::Ptr<CvMat> prevParam;
|
||||||
|
cv::Ptr<CvMat> param;
|
||||||
|
cv::Ptr<CvMat> J;
|
||||||
|
cv::Ptr<CvMat> err;
|
||||||
|
cv::Ptr<CvMat> JtJ;
|
||||||
|
cv::Ptr<CvMat> JtJN;
|
||||||
|
cv::Ptr<CvMat> JtErr;
|
||||||
|
cv::Ptr<CvMat> JtJV;
|
||||||
|
cv::Ptr<CvMat> JtJW;
|
||||||
|
double prevErrNorm, errNorm;
|
||||||
|
int lambdaLg10;
|
||||||
|
CvTermCriteria criteria;
|
||||||
|
int state;
|
||||||
|
int iters;
|
||||||
|
bool completeSymmFlag;
|
||||||
|
int solveMethod;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* OPENCV_CALIB3D_C_H */
|
@ -0,0 +1,678 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_AFFINE3_HPP
|
||||||
|
#define OPENCV_CORE_AFFINE3_HPP
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <opencv2/core.hpp>
|
||||||
|
|
||||||
|
namespace cv
|
||||||
|
{
|
||||||
|
|
||||||
|
//! @addtogroup core
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/** @brief Affine transform
|
||||||
|
*
|
||||||
|
* It represents a 4x4 homogeneous transformation matrix \f$T\f$
|
||||||
|
*
|
||||||
|
* \f[T =
|
||||||
|
* \begin{bmatrix}
|
||||||
|
* R & t\\
|
||||||
|
* 0 & 1\\
|
||||||
|
* \end{bmatrix}
|
||||||
|
* \f]
|
||||||
|
*
|
||||||
|
* where \f$R\f$ is a 3x3 rotation matrix and \f$t\f$ is a 3x1 translation vector.
|
||||||
|
*
|
||||||
|
* You can specify \f$R\f$ either by a 3x3 rotation matrix or by a 3x1 rotation vector,
|
||||||
|
* which is converted to a 3x3 rotation matrix by the Rodrigues formula.
|
||||||
|
*
|
||||||
|
* To construct a matrix \f$T\f$ representing first rotation around the axis \f$r\f$ with rotation
|
||||||
|
* angle \f$|r|\f$ in radian (right hand rule) and then translation by the vector \f$t\f$, you can use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Vec3f r, t;
|
||||||
|
* cv::Affine3f T(r, t);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* If you already have the rotation matrix \f$R\f$, then you can use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Matx33f R;
|
||||||
|
* cv::Affine3f T(R, t);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* To extract the rotation matrix \f$R\f$ from \f$T\f$, use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Matx33f R = T.rotation();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* To extract the translation vector \f$t\f$ from \f$T\f$, use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Vec3f t = T.translation();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* To extract the rotation vector \f$r\f$ from \f$T\f$, use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Vec3f r = T.rvec();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* Note that since the mapping from rotation vectors to rotation matrices
|
||||||
|
* is many to one. The returned rotation vector is not necessarily the one
|
||||||
|
* you used before to set the matrix.
|
||||||
|
*
|
||||||
|
* If you have two transformations \f$T = T_1 * T_2\f$, use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Affine3f T, T1, T2;
|
||||||
|
* T = T2.concatenate(T1);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* To get the inverse transform of \f$T\f$, use
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* cv::Affine3f T, T_inv;
|
||||||
|
* T_inv = T.inv();
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
class Affine3
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef T float_type;
|
||||||
|
typedef Matx<float_type, 3, 3> Mat3;
|
||||||
|
typedef Matx<float_type, 4, 4> Mat4;
|
||||||
|
typedef Vec<float_type, 3> Vec3;
|
||||||
|
|
||||||
|
//! Default constructor. It represents a 4x4 identity matrix.
|
||||||
|
Affine3();
|
||||||
|
|
||||||
|
//! Augmented affine matrix
|
||||||
|
Affine3(const Mat4& affine);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The resulting 4x4 matrix is
|
||||||
|
*
|
||||||
|
* \f[
|
||||||
|
* \begin{bmatrix}
|
||||||
|
* R & t\\
|
||||||
|
* 0 & 1\\
|
||||||
|
* \end{bmatrix}
|
||||||
|
* \f]
|
||||||
|
*
|
||||||
|
* @param R 3x3 rotation matrix.
|
||||||
|
* @param t 3x1 translation vector.
|
||||||
|
*/
|
||||||
|
Affine3(const Mat3& R, const Vec3& t = Vec3::all(0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rodrigues vector.
|
||||||
|
*
|
||||||
|
* The last row of the current matrix is set to [0,0,0,1].
|
||||||
|
*
|
||||||
|
* @param rvec 3x1 rotation vector. Its direction indicates the rotation axis and its length
|
||||||
|
* indicates the rotation angle in radian (using right hand rule).
|
||||||
|
* @param t 3x1 translation vector.
|
||||||
|
*/
|
||||||
|
Affine3(const Vec3& rvec, const Vec3& t = Vec3::all(0));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines all constructors above. Supports 4x4, 3x4, 3x3, 1x3, 3x1 sizes of data matrix.
|
||||||
|
*
|
||||||
|
* The last row of the current matrix is set to [0,0,0,1] when data is not 4x4.
|
||||||
|
*
|
||||||
|
* @param data 1-channel matrix.
|
||||||
|
* when it is 4x4, it is copied to the current matrix and t is not used.
|
||||||
|
* When it is 3x4, it is copied to the upper part 3x4 of the current matrix and t is not used.
|
||||||
|
* When it is 3x3, it is copied to the upper left 3x3 part of the current matrix.
|
||||||
|
* When it is 3x1 or 1x3, it is treated as a rotation vector and the Rodrigues formula is used
|
||||||
|
* to compute a 3x3 rotation matrix.
|
||||||
|
* @param t 3x1 translation vector. It is used only when data is neither 4x4 nor 3x4.
|
||||||
|
*/
|
||||||
|
explicit Affine3(const Mat& data, const Vec3& t = Vec3::all(0));
|
||||||
|
|
||||||
|
//! From 16-element array
|
||||||
|
explicit Affine3(const float_type* vals);
|
||||||
|
|
||||||
|
//! Create an 4x4 identity transform
|
||||||
|
static Affine3 Identity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rotation matrix.
|
||||||
|
*
|
||||||
|
* Copy the rotation matrix to the upper left 3x3 part of the current matrix.
|
||||||
|
* The remaining elements of the current matrix are not changed.
|
||||||
|
*
|
||||||
|
* @param R 3x3 rotation matrix.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void rotation(const Mat3& R);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rodrigues vector.
|
||||||
|
*
|
||||||
|
* It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
|
||||||
|
*
|
||||||
|
* @param rvec 3x1 rotation vector. The direction indicates the rotation axis and
|
||||||
|
* its length indicates the rotation angle in radian (using the right thumb convention).
|
||||||
|
*/
|
||||||
|
void rotation(const Vec3& rvec);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix.
|
||||||
|
*
|
||||||
|
* It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
|
||||||
|
*
|
||||||
|
* @param data 1-channel matrix.
|
||||||
|
* When it is a 3x3 matrix, it sets the upper left 3x3 part of the current matrix.
|
||||||
|
* When it is a 1x3 or 3x1 matrix, it is used as a rotation vector. The Rodrigues formula
|
||||||
|
* is used to compute the rotation matrix and sets the upper left 3x3 part of the current matrix.
|
||||||
|
*/
|
||||||
|
void rotation(const Mat& data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the 3x3 matrix L to the upper left part of the current matrix
|
||||||
|
*
|
||||||
|
* It sets the upper left 3x3 part of the matrix. The remaining part is unaffected.
|
||||||
|
*
|
||||||
|
* @param L 3x3 matrix.
|
||||||
|
*/
|
||||||
|
void linear(const Mat3& L);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy t to the first three elements of the last column of the current matrix
|
||||||
|
*
|
||||||
|
* It sets the upper right 3x1 part of the matrix. The remaining part is unaffected.
|
||||||
|
*
|
||||||
|
* @param t 3x1 translation vector.
|
||||||
|
*/
|
||||||
|
void translation(const Vec3& t);
|
||||||
|
|
||||||
|
//! @return the upper left 3x3 part
|
||||||
|
Mat3 rotation() const;
|
||||||
|
|
||||||
|
//! @return the upper left 3x3 part
|
||||||
|
Mat3 linear() const;
|
||||||
|
|
||||||
|
//! @return the upper right 3x1 part
|
||||||
|
Vec3 translation() const;
|
||||||
|
|
||||||
|
//! Rodrigues vector.
|
||||||
|
//! @return a vector representing the upper left 3x3 rotation matrix of the current matrix.
|
||||||
|
//! @warning Since the mapping between rotation vectors and rotation matrices is many to one,
|
||||||
|
//! this function returns only one rotation vector that represents the current rotation matrix,
|
||||||
|
//! which is not necessarily the same one set by `rotation(const Vec3& rvec)`.
|
||||||
|
Vec3 rvec() const;
|
||||||
|
|
||||||
|
//! @return the inverse of the current matrix.
|
||||||
|
Affine3 inv(int method = cv::DECOMP_SVD) const;
|
||||||
|
|
||||||
|
//! a.rotate(R) is equivalent to Affine(R, 0) * a;
|
||||||
|
Affine3 rotate(const Mat3& R) const;
|
||||||
|
|
||||||
|
//! a.rotate(rvec) is equivalent to Affine(rvec, 0) * a;
|
||||||
|
Affine3 rotate(const Vec3& rvec) const;
|
||||||
|
|
||||||
|
//! a.translate(t) is equivalent to Affine(E, t) * a, where E is an identity matrix
|
||||||
|
Affine3 translate(const Vec3& t) const;
|
||||||
|
|
||||||
|
//! a.concatenate(affine) is equivalent to affine * a;
|
||||||
|
Affine3 concatenate(const Affine3& affine) const;
|
||||||
|
|
||||||
|
template <typename Y> operator Affine3<Y>() const;
|
||||||
|
|
||||||
|
template <typename Y> Affine3<Y> cast() const;
|
||||||
|
|
||||||
|
Mat4 matrix;
|
||||||
|
|
||||||
|
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
|
||||||
|
Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine);
|
||||||
|
Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine);
|
||||||
|
operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const;
|
||||||
|
operator Eigen::Transform<T, 3, Eigen::Affine>() const;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T> static
|
||||||
|
Affine3<T> operator*(const Affine3<T>& affine1, const Affine3<T>& affine2);
|
||||||
|
|
||||||
|
//! V is a 3-element vector with member fields x, y and z
|
||||||
|
template<typename T, typename V> static
|
||||||
|
V operator*(const Affine3<T>& affine, const V& vector);
|
||||||
|
|
||||||
|
typedef Affine3<float> Affine3f;
|
||||||
|
typedef Affine3<double> Affine3d;
|
||||||
|
|
||||||
|
static Vec3f operator*(const Affine3f& affine, const Vec3f& vector);
|
||||||
|
static Vec3d operator*(const Affine3d& affine, const Vec3d& vector);
|
||||||
|
|
||||||
|
template<typename _Tp> class DataType< Affine3<_Tp> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef Affine3<_Tp> value_type;
|
||||||
|
typedef Affine3<typename DataType<_Tp>::work_type> work_type;
|
||||||
|
typedef _Tp channel_type;
|
||||||
|
|
||||||
|
enum { generic_type = 0,
|
||||||
|
channels = 16,
|
||||||
|
fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
|
||||||
|
#ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
|
||||||
|
,depth = DataType<channel_type>::depth
|
||||||
|
,type = CV_MAKETYPE(depth, channels)
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Vec<channel_type, channels> vec_type;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace traits {
|
||||||
|
template<typename _Tp>
|
||||||
|
struct Depth< Affine3<_Tp> > { enum { value = Depth<_Tp>::value }; };
|
||||||
|
template<typename _Tp>
|
||||||
|
struct Type< Affine3<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 16) }; };
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
//! @} core
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Implementation
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3()
|
||||||
|
: matrix(Mat4::eye())
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const Mat4& affine)
|
||||||
|
: matrix(affine)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const Mat3& R, const Vec3& t)
|
||||||
|
{
|
||||||
|
rotation(R);
|
||||||
|
translation(t);
|
||||||
|
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||||
|
matrix.val[15] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const Vec3& _rvec, const Vec3& t)
|
||||||
|
{
|
||||||
|
rotation(_rvec);
|
||||||
|
translation(t);
|
||||||
|
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||||
|
matrix.val[15] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
|
||||||
|
{
|
||||||
|
CV_Assert(data.type() == cv::traits::Type<T>::value);
|
||||||
|
CV_Assert(data.channels() == 1);
|
||||||
|
|
||||||
|
if (data.cols == 4 && data.rows == 4)
|
||||||
|
{
|
||||||
|
data.copyTo(matrix);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (data.cols == 4 && data.rows == 3)
|
||||||
|
{
|
||||||
|
rotation(data(Rect(0, 0, 3, 3)));
|
||||||
|
translation(data(Rect(3, 0, 1, 3)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rotation(data);
|
||||||
|
translation(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||||
|
matrix.val[15] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const float_type* vals) : matrix(vals)
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::Identity()
|
||||||
|
{
|
||||||
|
return Affine3<T>(cv::Affine3<T>::Mat4::eye());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
void cv::Affine3<T>::rotation(const Mat3& R)
|
||||||
|
{
|
||||||
|
linear(R);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
void cv::Affine3<T>::rotation(const Vec3& _rvec)
|
||||||
|
{
|
||||||
|
double theta = norm(_rvec);
|
||||||
|
|
||||||
|
if (theta < DBL_EPSILON)
|
||||||
|
rotation(Mat3::eye());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double c = std::cos(theta);
|
||||||
|
double s = std::sin(theta);
|
||||||
|
double c1 = 1. - c;
|
||||||
|
double itheta = (theta != 0) ? 1./theta : 0.;
|
||||||
|
|
||||||
|
Point3_<T> r = _rvec*itheta;
|
||||||
|
|
||||||
|
Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z );
|
||||||
|
Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 );
|
||||||
|
|
||||||
|
// R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x]
|
||||||
|
// where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0]
|
||||||
|
Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x;
|
||||||
|
|
||||||
|
rotation(R);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Combines rotation methods above. Supports 3x3, 1x3, 3x1 sizes of data matrix;
|
||||||
|
template<typename T> inline
|
||||||
|
void cv::Affine3<T>::rotation(const cv::Mat& data)
|
||||||
|
{
|
||||||
|
CV_Assert(data.type() == cv::traits::Type<T>::value);
|
||||||
|
CV_Assert(data.channels() == 1);
|
||||||
|
|
||||||
|
if (data.cols == 3 && data.rows == 3)
|
||||||
|
{
|
||||||
|
Mat3 R;
|
||||||
|
data.copyTo(R);
|
||||||
|
rotation(R);
|
||||||
|
}
|
||||||
|
else if ((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3))
|
||||||
|
{
|
||||||
|
Vec3 _rvec;
|
||||||
|
data.reshape(1, 3).copyTo(_rvec);
|
||||||
|
rotation(_rvec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
CV_Error(Error::StsError, "Input matrix can only be 3x3, 1x3 or 3x1");
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
void cv::Affine3<T>::linear(const Mat3& L)
|
||||||
|
{
|
||||||
|
matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2];
|
||||||
|
matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5];
|
||||||
|
matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
void cv::Affine3<T>::translation(const Vec3& t)
|
||||||
|
{
|
||||||
|
matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
typename cv::Affine3<T>::Mat3 cv::Affine3<T>::rotation() const
|
||||||
|
{
|
||||||
|
return linear();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
typename cv::Affine3<T>::Mat3 cv::Affine3<T>::linear() const
|
||||||
|
{
|
||||||
|
typename cv::Affine3<T>::Mat3 R;
|
||||||
|
R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2];
|
||||||
|
R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6];
|
||||||
|
R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10];
|
||||||
|
return R;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
typename cv::Affine3<T>::Vec3 cv::Affine3<T>::translation() const
|
||||||
|
{
|
||||||
|
return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
typename cv::Affine3<T>::Vec3 cv::Affine3<T>::rvec() const
|
||||||
|
{
|
||||||
|
cv::Vec3d w;
|
||||||
|
cv::Matx33d u, vt, R = rotation();
|
||||||
|
cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);
|
||||||
|
R = u * vt;
|
||||||
|
|
||||||
|
double rx = R.val[7] - R.val[5];
|
||||||
|
double ry = R.val[2] - R.val[6];
|
||||||
|
double rz = R.val[3] - R.val[1];
|
||||||
|
|
||||||
|
double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25);
|
||||||
|
double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5;
|
||||||
|
c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c;
|
||||||
|
double theta = std::acos(c);
|
||||||
|
|
||||||
|
if( s < 1e-5 )
|
||||||
|
{
|
||||||
|
if( c > 0 )
|
||||||
|
rx = ry = rz = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double t;
|
||||||
|
t = (R.val[0] + 1) * 0.5;
|
||||||
|
rx = std::sqrt(std::max(t, 0.0));
|
||||||
|
t = (R.val[4] + 1) * 0.5;
|
||||||
|
ry = std::sqrt(std::max(t, 0.0)) * (R.val[1] < 0 ? -1.0 : 1.0);
|
||||||
|
t = (R.val[8] + 1) * 0.5;
|
||||||
|
rz = std::sqrt(std::max(t, 0.0)) * (R.val[2] < 0 ? -1.0 : 1.0);
|
||||||
|
|
||||||
|
if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) )
|
||||||
|
rz = -rz;
|
||||||
|
theta /= std::sqrt(rx*rx + ry*ry + rz*rz);
|
||||||
|
rx *= theta;
|
||||||
|
ry *= theta;
|
||||||
|
rz *= theta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double vth = 1/(2*s);
|
||||||
|
vth *= theta;
|
||||||
|
rx *= vth; ry *= vth; rz *= vth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cv::Vec3d(rx, ry, rz);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::inv(int method) const
|
||||||
|
{
|
||||||
|
return matrix.inv(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::rotate(const Mat3& R) const
|
||||||
|
{
|
||||||
|
Mat3 Lc = linear();
|
||||||
|
Vec3 tc = translation();
|
||||||
|
Mat4 result;
|
||||||
|
result.val[12] = result.val[13] = result.val[14] = 0;
|
||||||
|
result.val[15] = 1;
|
||||||
|
|
||||||
|
for(int j = 0; j < 3; ++j)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
float_type value = 0;
|
||||||
|
for(int k = 0; k < 3; ++k)
|
||||||
|
value += R(j, k) * Lc(k, i);
|
||||||
|
result(j, i) = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
result(j, 3) = R.row(j).dot(tc.t());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::rotate(const Vec3& _rvec) const
|
||||||
|
{
|
||||||
|
return rotate(Affine3f(_rvec).rotation());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::translate(const Vec3& t) const
|
||||||
|
{
|
||||||
|
Mat4 m = matrix;
|
||||||
|
m.val[ 3] += t[0];
|
||||||
|
m.val[ 7] += t[1];
|
||||||
|
m.val[11] += t[2];
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::Affine3<T>::concatenate(const Affine3<T>& affine) const
|
||||||
|
{
|
||||||
|
return (*this).rotate(affine.rotation()).translate(affine.translation());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> template <typename Y> inline
|
||||||
|
cv::Affine3<T>::operator Affine3<Y>() const
|
||||||
|
{
|
||||||
|
return Affine3<Y>(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> template <typename Y> inline
|
||||||
|
cv::Affine3<Y> cv::Affine3<T>::cast() const
|
||||||
|
{
|
||||||
|
return Affine3<Y>(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2)
|
||||||
|
{
|
||||||
|
return affine2.concatenate(affine1);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename V> inline
|
||||||
|
V cv::operator*(const cv::Affine3<T>& affine, const V& v)
|
||||||
|
{
|
||||||
|
const typename Affine3<T>::Mat4& m = affine.matrix;
|
||||||
|
|
||||||
|
V r;
|
||||||
|
r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3];
|
||||||
|
r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7];
|
||||||
|
r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11];
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v)
|
||||||
|
{
|
||||||
|
const cv::Matx44f& m = affine.matrix;
|
||||||
|
cv::Vec3f r;
|
||||||
|
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
|
||||||
|
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
|
||||||
|
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v)
|
||||||
|
{
|
||||||
|
const cv::Matx44d& m = affine.matrix;
|
||||||
|
cv::Vec3d r;
|
||||||
|
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
|
||||||
|
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
|
||||||
|
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
|
||||||
|
{
|
||||||
|
cv::Mat(4, 4, cv::traits::Type<T>::value, affine.matrix().data()).copyTo(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine)
|
||||||
|
{
|
||||||
|
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
|
||||||
|
cv::Mat(4, 4, cv::traits::Type<T>::value, a.matrix().data()).copyTo(matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const
|
||||||
|
{
|
||||||
|
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r;
|
||||||
|
cv::Mat hdr(4, 4, cv::traits::Type<T>::value, r.matrix().data());
|
||||||
|
cv::Mat(matrix, false).copyTo(hdr);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T> inline
|
||||||
|
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine>() const
|
||||||
|
{
|
||||||
|
return this->operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H */
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif /* OPENCV_CORE_AFFINE3_HPP */
|
@ -0,0 +1,105 @@
|
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_ASYNC_HPP
|
||||||
|
#define OPENCV_CORE_ASYNC_HPP
|
||||||
|
|
||||||
|
#include <opencv2/core/mat.hpp>
|
||||||
|
|
||||||
|
#ifdef CV_CXX11
|
||||||
|
//#include <future>
|
||||||
|
#include <chrono>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace cv {
|
||||||
|
|
||||||
|
/** @addtogroup core_async
|
||||||
|
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/** @brief Returns result of asynchronous operations
|
||||||
|
|
||||||
|
Object has attached asynchronous state.
|
||||||
|
Assignment operator doesn't clone asynchronous state (it is shared between all instances).
|
||||||
|
|
||||||
|
Result can be fetched via get() method only once.
|
||||||
|
|
||||||
|
*/
|
||||||
|
class CV_EXPORTS_W AsyncArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~AsyncArray() CV_NOEXCEPT;
|
||||||
|
CV_WRAP AsyncArray() CV_NOEXCEPT;
|
||||||
|
AsyncArray(const AsyncArray& o) CV_NOEXCEPT;
|
||||||
|
AsyncArray& operator=(const AsyncArray& o) CV_NOEXCEPT;
|
||||||
|
CV_WRAP void release() CV_NOEXCEPT;
|
||||||
|
|
||||||
|
/** Fetch the result.
|
||||||
|
@param[out] dst destination array
|
||||||
|
|
||||||
|
Waits for result until container has valid result.
|
||||||
|
Throws exception if exception was stored as a result.
|
||||||
|
|
||||||
|
Throws exception on invalid container state.
|
||||||
|
|
||||||
|
@note Result or stored exception can be fetched only once.
|
||||||
|
*/
|
||||||
|
CV_WRAP void get(OutputArray dst) const;
|
||||||
|
|
||||||
|
/** Retrieving the result with timeout
|
||||||
|
@param[out] dst destination array
|
||||||
|
@param[in] timeoutNs timeout in nanoseconds, -1 for infinite wait
|
||||||
|
|
||||||
|
@returns true if result is ready, false if the timeout has expired
|
||||||
|
|
||||||
|
@note Result or stored exception can be fetched only once.
|
||||||
|
*/
|
||||||
|
bool get(OutputArray dst, int64 timeoutNs) const;
|
||||||
|
|
||||||
|
CV_WRAP inline
|
||||||
|
bool get(OutputArray dst, double timeoutNs) const { return get(dst, (int64)timeoutNs); }
|
||||||
|
|
||||||
|
bool wait_for(int64 timeoutNs) const;
|
||||||
|
|
||||||
|
CV_WRAP inline
|
||||||
|
bool wait_for(double timeoutNs) const { return wait_for((int64)timeoutNs); }
|
||||||
|
|
||||||
|
CV_WRAP bool valid() const CV_NOEXCEPT;
|
||||||
|
|
||||||
|
#ifdef CV_CXX11
|
||||||
|
inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; }
|
||||||
|
inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; }
|
||||||
|
|
||||||
|
template<typename _Rep, typename _Period>
|
||||||
|
inline bool get(OutputArray dst, const std::chrono::duration<_Rep, _Period>& timeout)
|
||||||
|
{
|
||||||
|
return get(dst, (int64)(std::chrono::nanoseconds(timeout).count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Rep, typename _Period>
|
||||||
|
inline bool wait_for(const std::chrono::duration<_Rep, _Period>& timeout)
|
||||||
|
{
|
||||||
|
return wait_for((int64)(std::chrono::nanoseconds(timeout).count()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
std::future<Mat> getFutureMat() const;
|
||||||
|
std::future<UMat> getFutureUMat() const;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// PImpl
|
||||||
|
struct Impl; friend struct Impl;
|
||||||
|
inline void* _getImpl() const CV_NOEXCEPT { return p; }
|
||||||
|
protected:
|
||||||
|
Impl* p;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
} // namespace
|
||||||
|
#endif // OPENCV_CORE_ASYNC_HPP
|
@ -0,0 +1,664 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// Copyright (C) 2014, Itseez Inc., all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_BASE_HPP
|
||||||
|
#define OPENCV_CORE_BASE_HPP
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
# error base.hpp header must be compiled as C++
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "opencv2/opencv_modules.hpp"
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "opencv2/core/cvdef.h"
|
||||||
|
#include "opencv2/core/cvstd.hpp"
|
||||||
|
|
||||||
|
namespace cv
|
||||||
|
{
|
||||||
|
|
||||||
|
//! @addtogroup core_utils
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
namespace Error {
|
||||||
|
//! error codes
|
||||||
|
enum Code {
|
||||||
|
StsOk= 0, //!< everything is ok
|
||||||
|
StsBackTrace= -1, //!< pseudo error for back trace
|
||||||
|
StsError= -2, //!< unknown /unspecified error
|
||||||
|
StsInternal= -3, //!< internal error (bad state)
|
||||||
|
StsNoMem= -4, //!< insufficient memory
|
||||||
|
StsBadArg= -5, //!< function arg/param is bad
|
||||||
|
StsBadFunc= -6, //!< unsupported function
|
||||||
|
StsNoConv= -7, //!< iteration didn't converge
|
||||||
|
StsAutoTrace= -8, //!< tracing
|
||||||
|
HeaderIsNull= -9, //!< image header is NULL
|
||||||
|
BadImageSize= -10, //!< image size is invalid
|
||||||
|
BadOffset= -11, //!< offset is invalid
|
||||||
|
BadDataPtr= -12, //!<
|
||||||
|
BadStep= -13, //!< image step is wrong, this may happen for a non-continuous matrix.
|
||||||
|
BadModelOrChSeq= -14, //!<
|
||||||
|
BadNumChannels= -15, //!< bad number of channels, for example, some functions accept only single channel matrices.
|
||||||
|
BadNumChannel1U= -16, //!<
|
||||||
|
BadDepth= -17, //!< input image depth is not supported by the function
|
||||||
|
BadAlphaChannel= -18, //!<
|
||||||
|
BadOrder= -19, //!< number of dimensions is out of range
|
||||||
|
BadOrigin= -20, //!< incorrect input origin
|
||||||
|
BadAlign= -21, //!< incorrect input align
|
||||||
|
BadCallBack= -22, //!<
|
||||||
|
BadTileSize= -23, //!<
|
||||||
|
BadCOI= -24, //!< input COI is not supported
|
||||||
|
BadROISize= -25, //!< incorrect input roi
|
||||||
|
MaskIsTiled= -26, //!<
|
||||||
|
StsNullPtr= -27, //!< null pointer
|
||||||
|
StsVecLengthErr= -28, //!< incorrect vector length
|
||||||
|
StsFilterStructContentErr= -29, //!< incorrect filter structure content
|
||||||
|
StsKernelStructContentErr= -30, //!< incorrect transform kernel content
|
||||||
|
StsFilterOffsetErr= -31, //!< incorrect filter offset value
|
||||||
|
StsBadSize= -201, //!< the input/output structure size is incorrect
|
||||||
|
StsDivByZero= -202, //!< division by zero
|
||||||
|
StsInplaceNotSupported= -203, //!< in-place operation is not supported
|
||||||
|
StsObjectNotFound= -204, //!< request can't be completed
|
||||||
|
StsUnmatchedFormats= -205, //!< formats of input/output arrays differ
|
||||||
|
StsBadFlag= -206, //!< flag is wrong or not supported
|
||||||
|
StsBadPoint= -207, //!< bad CvPoint
|
||||||
|
StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
|
||||||
|
StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match
|
||||||
|
StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function
|
||||||
|
StsOutOfRange= -211, //!< some of parameters are out of range
|
||||||
|
StsParseError= -212, //!< invalid syntax/structure of the parsed file
|
||||||
|
StsNotImplemented= -213, //!< the requested function/feature is not implemented
|
||||||
|
StsBadMemBlock= -214, //!< an allocated block has been corrupted
|
||||||
|
StsAssert= -215, //!< assertion failed
|
||||||
|
GpuNotSupported= -216, //!< no CUDA support
|
||||||
|
GpuApiCallError= -217, //!< GPU API call error
|
||||||
|
OpenGlNotSupported= -218, //!< no OpenGL support
|
||||||
|
OpenGlApiCallError= -219, //!< OpenGL API call error
|
||||||
|
OpenCLApiCallError= -220, //!< OpenCL API call error
|
||||||
|
OpenCLDoubleNotSupported= -221,
|
||||||
|
OpenCLInitError= -222, //!< OpenCL initialization error
|
||||||
|
OpenCLNoAMDBlasFft= -223
|
||||||
|
};
|
||||||
|
} //Error
|
||||||
|
|
||||||
|
//! @} core_utils
|
||||||
|
|
||||||
|
//! @addtogroup core_array
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
//! matrix decomposition types
|
||||||
|
enum DecompTypes {
|
||||||
|
/** Gaussian elimination with the optimal pivot element chosen. */
|
||||||
|
DECOMP_LU = 0,
|
||||||
|
/** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix
|
||||||
|
src1 can be singular */
|
||||||
|
DECOMP_SVD = 1,
|
||||||
|
/** eigenvalue decomposition; the matrix src1 must be symmetrical */
|
||||||
|
DECOMP_EIG = 2,
|
||||||
|
/** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively
|
||||||
|
defined */
|
||||||
|
DECOMP_CHOLESKY = 3,
|
||||||
|
/** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */
|
||||||
|
DECOMP_QR = 4,
|
||||||
|
/** while all the previous flags are mutually exclusive, this flag can be used together with
|
||||||
|
any of the previous; it means that the normal equations
|
||||||
|
\f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are
|
||||||
|
solved instead of the original system
|
||||||
|
\f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */
|
||||||
|
DECOMP_NORMAL = 16
|
||||||
|
};
|
||||||
|
|
||||||
|
/** norm types
|
||||||
|
|
||||||
|
src1 and src2 denote input arrays.
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum NormTypes {
|
||||||
|
/**
|
||||||
|
\f[
|
||||||
|
norm = \forkthree
|
||||||
|
{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
|
||||||
|
{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
|
||||||
|
{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) }
|
||||||
|
\f]
|
||||||
|
*/
|
||||||
|
NORM_INF = 1,
|
||||||
|
/**
|
||||||
|
\f[
|
||||||
|
norm = \forkthree
|
||||||
|
{\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)}
|
||||||
|
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
|
||||||
|
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
|
||||||
|
\f]*/
|
||||||
|
NORM_L1 = 2,
|
||||||
|
/**
|
||||||
|
\f[
|
||||||
|
norm = \forkthree
|
||||||
|
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
|
||||||
|
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
|
||||||
|
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }
|
||||||
|
\f]
|
||||||
|
*/
|
||||||
|
NORM_L2 = 4,
|
||||||
|
/**
|
||||||
|
\f[
|
||||||
|
norm = \forkthree
|
||||||
|
{ \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)}
|
||||||
|
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) }
|
||||||
|
{ \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2SQR}\) }
|
||||||
|
\f]
|
||||||
|
*/
|
||||||
|
NORM_L2SQR = 5,
|
||||||
|
/**
|
||||||
|
In the case of one input array, calculates the Hamming distance of the array from zero,
|
||||||
|
In the case of two input arrays, calculates the Hamming distance between the arrays.
|
||||||
|
*/
|
||||||
|
NORM_HAMMING = 6,
|
||||||
|
/**
|
||||||
|
Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will
|
||||||
|
be added and treated as a single bit to be used in the same calculation as NORM_HAMMING.
|
||||||
|
*/
|
||||||
|
NORM_HAMMING2 = 7,
|
||||||
|
NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags
|
||||||
|
NORM_RELATIVE = 8, //!< flag
|
||||||
|
NORM_MINMAX = 32 //!< flag
|
||||||
|
};
|
||||||
|
|
||||||
|
//! comparison types
|
||||||
|
enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2.
|
||||||
|
CMP_GT = 1, //!< src1 is greater than src2.
|
||||||
|
CMP_GE = 2, //!< src1 is greater than or equal to src2.
|
||||||
|
CMP_LT = 3, //!< src1 is less than src2.
|
||||||
|
CMP_LE = 4, //!< src1 is less than or equal to src2.
|
||||||
|
CMP_NE = 5 //!< src1 is unequal to src2.
|
||||||
|
};
|
||||||
|
|
||||||
|
//! generalized matrix multiplication flags
|
||||||
|
enum GemmFlags { GEMM_1_T = 1, //!< transposes src1
|
||||||
|
GEMM_2_T = 2, //!< transposes src2
|
||||||
|
GEMM_3_T = 4 //!< transposes src3
|
||||||
|
};
|
||||||
|
|
||||||
|
enum DftFlags {
|
||||||
|
/** performs an inverse 1D or 2D transform instead of the default forward
|
||||||
|
transform. */
|
||||||
|
DFT_INVERSE = 1,
|
||||||
|
/** scales the result: divide it by the number of array elements. Normally, it is
|
||||||
|
combined with DFT_INVERSE. */
|
||||||
|
DFT_SCALE = 2,
|
||||||
|
/** performs a forward or inverse transform of every individual row of the input
|
||||||
|
matrix; this flag enables you to transform multiple vectors simultaneously and can be used to
|
||||||
|
decrease the overhead (which is sometimes several times larger than the processing itself) to
|
||||||
|
perform 3D and higher-dimensional transformations and so forth.*/
|
||||||
|
DFT_ROWS = 4,
|
||||||
|
/** performs a forward transformation of 1D or 2D real array; the result,
|
||||||
|
though being a complex array, has complex-conjugate symmetry (*CCS*, see the function
|
||||||
|
description below for details), and such an array can be packed into a real array of the same
|
||||||
|
size as input, which is the fastest option and which is what the function does by default;
|
||||||
|
however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) -
|
||||||
|
pass the flag to enable the function to produce a full-size complex output array. */
|
||||||
|
DFT_COMPLEX_OUTPUT = 16,
|
||||||
|
/** performs an inverse transformation of a 1D or 2D complex array; the
|
||||||
|
result is normally a complex array of the same size, however, if the input array has
|
||||||
|
conjugate-complex symmetry (for example, it is a result of forward transformation with
|
||||||
|
DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not
|
||||||
|
check whether the input is symmetrical or not, you can pass the flag and then the function
|
||||||
|
will assume the symmetry and produce the real output array (note that when the input is packed
|
||||||
|
into a real array and inverse transformation is executed, the function treats the input as a
|
||||||
|
packed complex-conjugate symmetrical array, and the output will also be a real array). */
|
||||||
|
DFT_REAL_OUTPUT = 32,
|
||||||
|
/** specifies that input is complex input. If this flag is set, the input must have 2 channels.
|
||||||
|
On the other hand, for backwards compatibility reason, if input has 2 channels, input is
|
||||||
|
already considered complex. */
|
||||||
|
DFT_COMPLEX_INPUT = 64,
|
||||||
|
/** performs an inverse 1D or 2D transform instead of the default forward transform. */
|
||||||
|
DCT_INVERSE = DFT_INVERSE,
|
||||||
|
/** performs a forward or inverse transform of every individual row of the input
|
||||||
|
matrix. This flag enables you to transform multiple vectors simultaneously and can be used to
|
||||||
|
decrease the overhead (which is sometimes several times larger than the processing itself) to
|
||||||
|
perform 3D and higher-dimensional transforms and so forth.*/
|
||||||
|
DCT_ROWS = DFT_ROWS
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Various border types, image boundaries are denoted with `|`
|
||||||
|
//! @see borderInterpolate, copyMakeBorder
|
||||||
|
enum BorderTypes {
|
||||||
|
BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i`
|
||||||
|
BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
|
||||||
|
BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb`
|
||||||
|
BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg`
|
||||||
|
BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
|
||||||
|
BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno`
|
||||||
|
|
||||||
|
BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
|
||||||
|
BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
|
||||||
|
BORDER_ISOLATED = 16 //!< do not look outside of ROI
|
||||||
|
};
|
||||||
|
|
||||||
|
//! @} core_array
|
||||||
|
|
||||||
|
//! @addtogroup core_utils
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! @brief Signals an error and raises the exception.
|
||||||
|
|
||||||
|
By default the function prints information about the error to stderr,
|
||||||
|
then it either stops if setBreakOnError() had been called before or raises the exception.
|
||||||
|
It is possible to alternate error processing by using redirectError().
|
||||||
|
@param _code - error code (Error::Code)
|
||||||
|
@param _err - error description
|
||||||
|
@param _func - function name. Available only when the compiler supports getting it
|
||||||
|
@param _file - source file name where the error has occurred
|
||||||
|
@param _line - line number in the source file where the error has occurred
|
||||||
|
@see CV_Error, CV_Error_, CV_Assert, CV_DbgAssert
|
||||||
|
*/
|
||||||
|
CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
|
||||||
|
|
||||||
|
#ifdef CV_STATIC_ANALYSIS
|
||||||
|
|
||||||
|
// In practice, some macro are not processed correctly (noreturn is not detected).
|
||||||
|
// We need to use simplified definition for them.
|
||||||
|
#define CV_Error(code, msg) do { (void)(code); (void)(msg); abort(); } while (0)
|
||||||
|
#define CV_Error_(code, args) do { (void)(code); (void)(cv::format args); abort(); } while (0)
|
||||||
|
#define CV_Assert( expr ) do { if (!(expr)) abort(); } while (0)
|
||||||
|
|
||||||
|
#else // CV_STATIC_ANALYSIS
|
||||||
|
|
||||||
|
/** @brief Call the error handler.
|
||||||
|
|
||||||
|
Currently, the error handler prints the error code and the error message to the standard
|
||||||
|
error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
|
||||||
|
the execution stack and all the parameters can be analyzed by the debugger. In the Release
|
||||||
|
configuration, the exception is thrown.
|
||||||
|
|
||||||
|
@param code one of Error::Code
|
||||||
|
@param msg error message
|
||||||
|
*/
|
||||||
|
#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
|
||||||
|
|
||||||
|
/** @brief Call the error handler.
|
||||||
|
|
||||||
|
This macro can be used to construct an error message on-fly to include some dynamic information,
|
||||||
|
for example:
|
||||||
|
@code
|
||||||
|
// note the extra parentheses around the formatted text message
|
||||||
|
CV_Error_(Error::StsOutOfRange,
|
||||||
|
("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
|
||||||
|
@endcode
|
||||||
|
@param code one of Error::Code
|
||||||
|
@param args printf-like formatted error message in parentheses
|
||||||
|
*/
|
||||||
|
#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
|
||||||
|
|
||||||
|
/** @brief Checks a condition at runtime and throws exception if it fails
|
||||||
|
|
||||||
|
The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
|
||||||
|
raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
|
||||||
|
configurations while CV_DbgAssert is only retained in the Debug configuration.
|
||||||
|
*/
|
||||||
|
#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
|
||||||
|
|
||||||
|
#endif // CV_STATIC_ANALYSIS
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
#if !defined(__OPENCV_BUILD) // TODO: backward compatibility only
|
||||||
|
#ifndef CV_ErrorNoReturn
|
||||||
|
#define CV_ErrorNoReturn CV_Error
|
||||||
|
#endif
|
||||||
|
#ifndef CV_ErrorNoReturn_
|
||||||
|
#define CV_ErrorNoReturn_ CV_Error_
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CV_Assert_1 CV_Assert
|
||||||
|
#define CV_Assert_2( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_1( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_3( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_2( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_4( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_3( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_5( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_4( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_6( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_5( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_7( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_6( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_8( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_7( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_9( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_8( __VA_ARGS__ ))
|
||||||
|
#define CV_Assert_10( expr, ... ) CV_Assert_1(expr); __CV_EXPAND(CV_Assert_9( __VA_ARGS__ ))
|
||||||
|
|
||||||
|
#define CV_Assert_N(...) do { __CV_EXPAND(__CV_CAT(CV_Assert_, __CV_VA_NUM_ARGS(__VA_ARGS__)) (__VA_ARGS__)); } while(0)
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#if defined _DEBUG || defined CV_STATIC_ANALYSIS
|
||||||
|
# define CV_DbgAssert(expr) CV_Assert(expr)
|
||||||
|
#else
|
||||||
|
/** replaced with CV_Assert(expr) in Debug configuration */
|
||||||
|
# define CV_DbgAssert(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
||||||
|
* bit count of A exclusive XOR'ed with B
|
||||||
|
*/
|
||||||
|
struct CV_EXPORTS Hamming
|
||||||
|
{
|
||||||
|
static const NormTypes normType = NORM_HAMMING;
|
||||||
|
typedef unsigned char ValueType;
|
||||||
|
typedef int ResultType;
|
||||||
|
|
||||||
|
/** this will count the bits in a ^ b
|
||||||
|
*/
|
||||||
|
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Hamming HammingLUT;
|
||||||
|
|
||||||
|
/////////////////////////////////// inline norms ////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); }
|
||||||
|
inline int cv_abs(uchar x) { return x; }
|
||||||
|
inline int cv_abs(schar x) { return std::abs(x); }
|
||||||
|
inline int cv_abs(ushort x) { return x; }
|
||||||
|
inline int cv_abs(short x) { return std::abs(x); }
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normL2Sqr(const _Tp* a, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
int i=0;
|
||||||
|
#if CV_ENABLE_UNROLLED
|
||||||
|
for( ; i <= n - 4; i += 4 )
|
||||||
|
{
|
||||||
|
_AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
|
||||||
|
s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for( ; i < n; i++ )
|
||||||
|
{
|
||||||
|
_AccTp v = a[i];
|
||||||
|
s += v*v;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normL1(const _Tp* a, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
int i = 0;
|
||||||
|
#if CV_ENABLE_UNROLLED
|
||||||
|
for(; i <= n - 4; i += 4 )
|
||||||
|
{
|
||||||
|
s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) +
|
||||||
|
(_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for( ; i < n; i++ )
|
||||||
|
s += cv_abs(a[i]);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normInf(const _Tp* a, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
s = std::max(s, (_AccTp)cv_abs(a[i]));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
int i= 0;
|
||||||
|
#if CV_ENABLE_UNROLLED
|
||||||
|
for(; i <= n - 4; i += 4 )
|
||||||
|
{
|
||||||
|
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||||
|
s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for( ; i < n; i++ )
|
||||||
|
{
|
||||||
|
_AccTp v = _AccTp(a[i] - b[i]);
|
||||||
|
s += v*v;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline float normL2Sqr(const float* a, const float* b, int n)
|
||||||
|
{
|
||||||
|
float s = 0.f;
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
float v = a[i] - b[i];
|
||||||
|
s += v*v;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normL1(const _Tp* a, const _Tp* b, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
int i= 0;
|
||||||
|
#if CV_ENABLE_UNROLLED
|
||||||
|
for(; i <= n - 4; i += 4 )
|
||||||
|
{
|
||||||
|
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||||
|
s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
for( ; i < n; i++ )
|
||||||
|
{
|
||||||
|
_AccTp v = _AccTp(a[i] - b[i]);
|
||||||
|
s += std::abs(v);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float normL1(const float* a, const float* b, int n)
|
||||||
|
{
|
||||||
|
float s = 0.f;
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
s += std::abs(a[i] - b[i]);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int normL1(const uchar* a, const uchar* b, int n)
|
||||||
|
{
|
||||||
|
int s = 0;
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
s += std::abs(a[i] - b[i]);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp, typename _AccTp> static inline
|
||||||
|
_AccTp normInf(const _Tp* a, const _Tp* b, int n)
|
||||||
|
{
|
||||||
|
_AccTp s = 0;
|
||||||
|
for( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
_AccTp v0 = a[i] - b[i];
|
||||||
|
s = std::max(s, std::abs(v0));
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Computes the cube root of an argument.
|
||||||
|
|
||||||
|
The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly.
|
||||||
|
NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for
|
||||||
|
single-precision data.
|
||||||
|
@param val A function argument.
|
||||||
|
*/
|
||||||
|
CV_EXPORTS_W float cubeRoot(float val);
|
||||||
|
|
||||||
|
/** @overload
|
||||||
|
|
||||||
|
cubeRoot with argument of `double` type calls `std::cbrt(double)`
|
||||||
|
*/
|
||||||
|
static inline
|
||||||
|
double cubeRoot(double val)
|
||||||
|
{
|
||||||
|
return std::cbrt(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief Calculates the angle of a 2D vector in degrees.
|
||||||
|
|
||||||
|
The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured
|
||||||
|
in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees.
|
||||||
|
@param x x-coordinate of the vector.
|
||||||
|
@param y y-coordinate of the vector.
|
||||||
|
*/
|
||||||
|
CV_EXPORTS_W float fastAtan2(float y, float x);
|
||||||
|
|
||||||
|
/** proxy for hal::LU */
|
||||||
|
CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||||
|
/** proxy for hal::LU */
|
||||||
|
CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||||
|
/** proxy for hal::Cholesky */
|
||||||
|
CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||||
|
/** proxy for hal::Cholesky */
|
||||||
|
CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||||
|
|
||||||
|
////////////////// forward declarations for important OpenCV types //////////////////
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
template<typename _Tp, int cn> class Vec;
|
||||||
|
template<typename _Tp, int m, int n> class Matx;
|
||||||
|
|
||||||
|
template<typename _Tp> class Complex;
|
||||||
|
template<typename _Tp> class Point_;
|
||||||
|
template<typename _Tp> class Point3_;
|
||||||
|
template<typename _Tp> class Size_;
|
||||||
|
template<typename _Tp> class Rect_;
|
||||||
|
template<typename _Tp> class Scalar_;
|
||||||
|
|
||||||
|
class CV_EXPORTS RotatedRect;
|
||||||
|
class CV_EXPORTS Range;
|
||||||
|
class CV_EXPORTS TermCriteria;
|
||||||
|
class CV_EXPORTS KeyPoint;
|
||||||
|
class CV_EXPORTS DMatch;
|
||||||
|
class CV_EXPORTS RNG;
|
||||||
|
|
||||||
|
class CV_EXPORTS Mat;
|
||||||
|
class CV_EXPORTS MatExpr;
|
||||||
|
|
||||||
|
class CV_EXPORTS UMat;
|
||||||
|
|
||||||
|
class CV_EXPORTS SparseMat;
|
||||||
|
typedef Mat MatND;
|
||||||
|
|
||||||
|
template<typename _Tp> class Mat_;
|
||||||
|
template<typename _Tp> class SparseMat_;
|
||||||
|
|
||||||
|
class CV_EXPORTS MatConstIterator;
|
||||||
|
class CV_EXPORTS SparseMatIterator;
|
||||||
|
class CV_EXPORTS SparseMatConstIterator;
|
||||||
|
template<typename _Tp> class MatIterator_;
|
||||||
|
template<typename _Tp> class MatConstIterator_;
|
||||||
|
template<typename _Tp> class SparseMatIterator_;
|
||||||
|
template<typename _Tp> class SparseMatConstIterator_;
|
||||||
|
|
||||||
|
namespace ogl
|
||||||
|
{
|
||||||
|
class CV_EXPORTS Buffer;
|
||||||
|
class CV_EXPORTS Texture2D;
|
||||||
|
class CV_EXPORTS Arrays;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cuda
|
||||||
|
{
|
||||||
|
class CV_EXPORTS GpuMat;
|
||||||
|
class CV_EXPORTS HostMem;
|
||||||
|
class CV_EXPORTS Stream;
|
||||||
|
class CV_EXPORTS Event;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cudev
|
||||||
|
{
|
||||||
|
template <typename _Tp> class GpuMat_;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace ipp
|
||||||
|
{
|
||||||
|
CV_EXPORTS unsigned long long getIppFeatures();
|
||||||
|
CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
|
||||||
|
int line = 0);
|
||||||
|
CV_EXPORTS int getIppStatus();
|
||||||
|
CV_EXPORTS String getIppErrorLocation();
|
||||||
|
CV_EXPORTS_W bool useIPP();
|
||||||
|
CV_EXPORTS_W void setUseIPP(bool flag);
|
||||||
|
CV_EXPORTS_W String getIppVersion();
|
||||||
|
|
||||||
|
// IPP Not-Exact mode. This function may force use of IPP then both IPP and OpenCV provide proper results
|
||||||
|
// but have internal accuracy differences which have too much direct or indirect impact on accuracy tests.
|
||||||
|
CV_EXPORTS_W bool useIPP_NotExact();
|
||||||
|
CV_EXPORTS_W void setUseIPP_NotExact(bool flag);
|
||||||
|
#ifndef DISABLE_OPENCV_3_COMPATIBILITY
|
||||||
|
static inline bool useIPP_NE() { return useIPP_NotExact(); }
|
||||||
|
static inline void setUseIPP_NE(bool flag) { setUseIPP_NotExact(flag); }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // ipp
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
//! @} core_utils
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // cv
|
||||||
|
|
||||||
|
#include "opencv2/core/neon_utils.hpp"
|
||||||
|
#include "opencv2/core/vsx_utils.hpp"
|
||||||
|
#include "opencv2/core/check.hpp"
|
||||||
|
|
||||||
|
#endif //OPENCV_CORE_BASE_HPP
|
@ -0,0 +1,352 @@
|
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_BINDINGS_UTILS_HPP
|
||||||
|
#define OPENCV_CORE_BINDINGS_UTILS_HPP
|
||||||
|
|
||||||
|
#include <opencv2/core/async.hpp>
|
||||||
|
#include <opencv2/core/detail/async_promise.hpp>
|
||||||
|
#include <opencv2/core/utils/logger.hpp>
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace cv { namespace utils {
|
||||||
|
//! @addtogroup core_utils
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpInputArray(InputArray argument);
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument);
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument);
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argument);
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpBool(bool argument)
|
||||||
|
{
|
||||||
|
return (argument) ? String("Bool: True") : String("Bool: False");
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpInt(int argument)
|
||||||
|
{
|
||||||
|
return cv::format("Int: %d", argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpInt64(int64 argument)
|
||||||
|
{
|
||||||
|
std::ostringstream oss("Int64: ", std::ios::ate);
|
||||||
|
oss << argument;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpSizeT(size_t argument)
|
||||||
|
{
|
||||||
|
std::ostringstream oss("size_t: ", std::ios::ate);
|
||||||
|
oss << argument;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpFloat(float argument)
|
||||||
|
{
|
||||||
|
return cv::format("Float: %.2f", argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpDouble(double argument)
|
||||||
|
{
|
||||||
|
return cv::format("Double: %.2f", argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpCString(const char* argument)
|
||||||
|
{
|
||||||
|
return cv::format("String: %s", argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpString(const String& argument)
|
||||||
|
{
|
||||||
|
return cv::format("String: %s", argument.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String testOverloadResolution(int value, const Point& point = Point(42, 24))
|
||||||
|
{
|
||||||
|
return format("overload (int=%d, point=(x=%d, y=%d))", value, point.x,
|
||||||
|
point.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String testOverloadResolution(const Rect& rect)
|
||||||
|
{
|
||||||
|
return format("overload (rect=(x=%d, y=%d, w=%d, h=%d))", rect.x, rect.y,
|
||||||
|
rect.width, rect.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpRect(const Rect& argument)
|
||||||
|
{
|
||||||
|
return format("rect: (x=%d, y=%d, w=%d, h=%d)", argument.x, argument.y,
|
||||||
|
argument.width, argument.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpTermCriteria(const TermCriteria& argument)
|
||||||
|
{
|
||||||
|
return format("term_criteria: (type=%d, max_count=%d, epsilon=%lf",
|
||||||
|
argument.type, argument.maxCount, argument.epsilon);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpRotatedRect(const RotatedRect& argument)
|
||||||
|
{
|
||||||
|
return format("rotated_rect: (c_x=%f, c_y=%f, w=%f, h=%f, a=%f)",
|
||||||
|
argument.center.x, argument.center.y, argument.size.width,
|
||||||
|
argument.size.height, argument.angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
RotatedRect testRotatedRect(float x, float y, float w, float h, float angle)
|
||||||
|
{
|
||||||
|
return RotatedRect(Point2f(x, y), Size2f(w, h), angle);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
std::vector<RotatedRect> testRotatedRectVector(float x, float y, float w, float h, float angle)
|
||||||
|
{
|
||||||
|
std::vector<RotatedRect> result;
|
||||||
|
for (int i = 0; i < 10; i++)
|
||||||
|
result.push_back(RotatedRect(Point2f(x + i, y + 2 * i), Size2f(w, h), angle + 10 * i));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpRange(const Range& argument)
|
||||||
|
{
|
||||||
|
if (argument == Range::all())
|
||||||
|
{
|
||||||
|
return "range: all";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return format("range: (s=%d, e=%d)", argument.start, argument.end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
int testOverwriteNativeMethod(int argument)
|
||||||
|
{
|
||||||
|
return argument;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String testReservedKeywordConversion(int positional_argument, int lambda = 2, int from = 3)
|
||||||
|
{
|
||||||
|
return format("arg=%d, lambda=%d, from=%d", positional_argument, lambda, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpVectorOfInt(const std::vector<int>& vec);
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpVectorOfDouble(const std::vector<double>& vec);
|
||||||
|
|
||||||
|
CV_EXPORTS_W String dumpVectorOfRect(const std::vector<Rect>& vec);
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
void generateVectorOfRect(size_t len, CV_OUT std::vector<Rect>& vec)
|
||||||
|
{
|
||||||
|
vec.resize(len);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
RNG rng(12345);
|
||||||
|
Mat tmp(static_cast<int>(len), 1, CV_32SC4);
|
||||||
|
rng.fill(tmp, RNG::UNIFORM, 10, 20);
|
||||||
|
tmp.copyTo(vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
void generateVectorOfInt(size_t len, CV_OUT std::vector<int>& vec)
|
||||||
|
{
|
||||||
|
vec.resize(len);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
RNG rng(554433);
|
||||||
|
Mat tmp(static_cast<int>(len), 1, CV_32SC1);
|
||||||
|
rng.fill(tmp, RNG::UNIFORM, -10, 10);
|
||||||
|
tmp.copyTo(vec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
void generateVectorOfMat(size_t len, int rows, int cols, int dtype, CV_OUT std::vector<Mat>& vec)
|
||||||
|
{
|
||||||
|
vec.resize(len);
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
RNG rng(65431);
|
||||||
|
for (size_t i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
vec[i].create(rows, cols, dtype);
|
||||||
|
rng.fill(vec[i], RNG::UNIFORM, 0, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
void testRaiseGeneralException()
|
||||||
|
{
|
||||||
|
throw std::runtime_error("exception text");
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
AsyncArray testAsyncArray(InputArray argument)
|
||||||
|
{
|
||||||
|
AsyncPromise p;
|
||||||
|
p.setValue(argument);
|
||||||
|
return p.getArrayResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
AsyncArray testAsyncException()
|
||||||
|
{
|
||||||
|
AsyncPromise p;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CV_Error(Error::StsOk, "Test: Generated async error");
|
||||||
|
}
|
||||||
|
catch (const cv::Exception& e)
|
||||||
|
{
|
||||||
|
p.setException(e);
|
||||||
|
}
|
||||||
|
return p.getArrayResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
String dumpVec2i(const cv::Vec2i value = cv::Vec2i(42, 24)) {
|
||||||
|
return format("Vec2i(%d, %d)", value[0], value[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CV_EXPORTS_W_SIMPLE ClassWithKeywordProperties {
|
||||||
|
CV_PROP_RW int lambda;
|
||||||
|
CV_PROP int except;
|
||||||
|
|
||||||
|
CV_WRAP explicit ClassWithKeywordProperties(int lambda_arg = 24, int except_arg = 42)
|
||||||
|
{
|
||||||
|
lambda = lambda_arg;
|
||||||
|
except = except_arg;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CV_EXPORTS_W_PARAMS FunctionParams
|
||||||
|
{
|
||||||
|
CV_PROP_RW int lambda = -1;
|
||||||
|
CV_PROP_RW float sigma = 0.0f;
|
||||||
|
|
||||||
|
FunctionParams& setLambda(int value) CV_NOEXCEPT
|
||||||
|
{
|
||||||
|
lambda = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
FunctionParams& setSigma(float value) CV_NOEXCEPT
|
||||||
|
{
|
||||||
|
sigma = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CV_WRAP static inline String
|
||||||
|
copyMatAndDumpNamedArguments(InputArray src, OutputArray dst,
|
||||||
|
const FunctionParams& params = FunctionParams())
|
||||||
|
{
|
||||||
|
src.copyTo(dst);
|
||||||
|
return format("lambda=%d, sigma=%.1f", params.lambda,
|
||||||
|
params.sigma);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace nested {
|
||||||
|
CV_WRAP static inline bool testEchoBooleanFunction(bool flag) {
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CV_EXPORTS_W CV_WRAP_AS(ExportClassName) OriginalClassName
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct CV_EXPORTS_W_SIMPLE Params
|
||||||
|
{
|
||||||
|
CV_PROP_RW int int_value;
|
||||||
|
CV_PROP_RW float float_value;
|
||||||
|
|
||||||
|
CV_WRAP explicit Params(int int_param = 123, float float_param = 3.5f)
|
||||||
|
{
|
||||||
|
int_value = int_param;
|
||||||
|
float_value = float_param;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit OriginalClassName(const OriginalClassName::Params& params = OriginalClassName::Params())
|
||||||
|
{
|
||||||
|
params_ = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP int getIntParam() const
|
||||||
|
{
|
||||||
|
return params_.int_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP float getFloatParam() const
|
||||||
|
{
|
||||||
|
return params_.float_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static std::string originalName()
|
||||||
|
{
|
||||||
|
return "OriginalClassName";
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static Ptr<OriginalClassName>
|
||||||
|
create(const OriginalClassName::Params& params = OriginalClassName::Params())
|
||||||
|
{
|
||||||
|
return makePtr<OriginalClassName>(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
OriginalClassName::Params params_;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef OriginalClassName::Params OriginalClassName_Params;
|
||||||
|
} // namespace nested
|
||||||
|
|
||||||
|
namespace fs {
|
||||||
|
CV_EXPORTS_W cv::String getCacheDirectoryForDownloads();
|
||||||
|
} // namespace fs
|
||||||
|
|
||||||
|
//! @} // core_utils
|
||||||
|
} // namespace cv::utils
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
int setLogLevel(int level)
|
||||||
|
{
|
||||||
|
// NB: Binding generators doesn't work with enums properly yet, so we define separate overload here
|
||||||
|
return cv::utils::logging::setLogLevel((cv::utils::logging::LogLevel)level);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_WRAP static inline
|
||||||
|
int getLogLevel()
|
||||||
|
{
|
||||||
|
return cv::utils::logging::getLogLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @endcond IGNORED
|
||||||
|
|
||||||
|
} // namespaces cv / utils
|
||||||
|
|
||||||
|
#endif // OPENCV_CORE_BINDINGS_UTILS_HPP
|
@ -0,0 +1,40 @@
|
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
//
|
||||||
|
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_BUFFER_POOL_HPP
|
||||||
|
#define OPENCV_CORE_BUFFER_POOL_HPP
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4265)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace cv
|
||||||
|
{
|
||||||
|
|
||||||
|
//! @addtogroup core
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
class BufferPoolController
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
~BufferPoolController() { }
|
||||||
|
public:
|
||||||
|
virtual size_t getReservedSize() const = 0;
|
||||||
|
virtual size_t getMaxReservedSize() const = 0;
|
||||||
|
virtual void setMaxReservedSize(size_t size) = 0;
|
||||||
|
virtual void freeAllReservedBuffers() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // OPENCV_CORE_BUFFER_POOL_HPP
|
@ -0,0 +1,170 @@
|
|||||||
|
// This file is part of OpenCV project.
|
||||||
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||||
|
// of this distribution and at http://opencv.org/license.html.
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_CHECK_HPP
|
||||||
|
#define OPENCV_CORE_CHECK_HPP
|
||||||
|
|
||||||
|
#include <opencv2/core/base.hpp>
|
||||||
|
|
||||||
|
namespace cv {
|
||||||
|
|
||||||
|
/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or "<invalid depth>" */
|
||||||
|
CV_EXPORTS const char* depthToString(int depth);
|
||||||
|
|
||||||
|
/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or "<invalid type>" */
|
||||||
|
CV_EXPORTS String typeToString(int type);
|
||||||
|
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
/** Returns string of cv::Mat depth value: CV_8U -> "CV_8U" or NULL */
|
||||||
|
CV_EXPORTS const char* depthToString_(int depth);
|
||||||
|
|
||||||
|
/** Returns string of cv::Mat depth value: CV_8UC3 -> "CV_8UC3" or cv::String() */
|
||||||
|
CV_EXPORTS cv::String typeToString_(int type);
|
||||||
|
|
||||||
|
enum TestOp {
|
||||||
|
TEST_CUSTOM = 0,
|
||||||
|
TEST_EQ = 1,
|
||||||
|
TEST_NE = 2,
|
||||||
|
TEST_LE = 3,
|
||||||
|
TEST_LT = 4,
|
||||||
|
TEST_GE = 5,
|
||||||
|
TEST_GT = 6,
|
||||||
|
CV__LAST_TEST_OP
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CheckContext {
|
||||||
|
const char* func;
|
||||||
|
const char* file;
|
||||||
|
int line;
|
||||||
|
enum TestOp testOp;
|
||||||
|
const char* message;
|
||||||
|
const char* p1_str;
|
||||||
|
const char* p2_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef CV__CHECK_FILENAME
|
||||||
|
# define CV__CHECK_FILENAME __FILE__
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CV__CHECK_FUNCTION
|
||||||
|
# if defined _MSC_VER
|
||||||
|
# define CV__CHECK_FUNCTION __FUNCSIG__
|
||||||
|
# elif defined __GNUC__
|
||||||
|
# define CV__CHECK_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
# else
|
||||||
|
# define CV__CHECK_FUNCTION "<unknown>"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CV__CHECK_LOCATION_VARNAME(id) CVAUX_CONCAT(CVAUX_CONCAT(__cv_check_, id), __LINE__)
|
||||||
|
#define CV__DEFINE_CHECK_CONTEXT(id, message, testOp, p1_str, p2_str) \
|
||||||
|
static const cv::detail::CheckContext CV__CHECK_LOCATION_VARNAME(id) = \
|
||||||
|
{ CV__CHECK_FUNCTION, CV__CHECK_FILENAME, __LINE__, testOp, "" message, "" p1_str, "" p2_str }
|
||||||
|
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const bool v1, const bool v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const int v1, const int v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const float v1, const float v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const double v1, const double v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_<int> v1, const Size_<int> v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v1, const int v2, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx);
|
||||||
|
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_true(const bool v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_false(const bool v, const CheckContext& ctx);
|
||||||
|
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const int v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const size_t v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const float v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const double v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const Size_<int> v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_auto(const std::string& v1, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatDepth(const int v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatType(const int v, const CheckContext& ctx);
|
||||||
|
CV_EXPORTS void CV_NORETURN check_failed_MatChannels(const int v, const CheckContext& ctx);
|
||||||
|
|
||||||
|
|
||||||
|
#define CV__TEST_EQ(v1, v2) ((v1) == (v2))
|
||||||
|
#define CV__TEST_NE(v1, v2) ((v1) != (v2))
|
||||||
|
#define CV__TEST_LE(v1, v2) ((v1) <= (v2))
|
||||||
|
#define CV__TEST_LT(v1, v2) ((v1) < (v2))
|
||||||
|
#define CV__TEST_GE(v1, v2) ((v1) >= (v2))
|
||||||
|
#define CV__TEST_GT(v1, v2) ((v1) > (v2))
|
||||||
|
|
||||||
|
#define CV__CHECK(id, op, type, v1, v2, v1_str, v2_str, msg_str) do { \
|
||||||
|
if(CV__TEST_##op((v1), (v2))) ; else { \
|
||||||
|
CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_ ## op, v1_str, v2_str); \
|
||||||
|
cv::detail::check_failed_ ## type((v1), (v2), CV__CHECK_LOCATION_VARNAME(id)); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define CV__CHECK_CUSTOM_TEST(id, type, v, test_expr, v_str, test_expr_str, msg_str) do { \
|
||||||
|
if(!!(test_expr)) ; else { \
|
||||||
|
CV__DEFINE_CHECK_CONTEXT(id, msg_str, cv::detail::TEST_CUSTOM, v_str, test_expr_str); \
|
||||||
|
cv::detail::check_failed_ ## type((v), CV__CHECK_LOCATION_VARNAME(id)); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
|
||||||
|
/// Supported values of these types: int, float, double
|
||||||
|
#define CV_CheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_CheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_CheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_CheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_CheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_CheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
|
||||||
|
/// Check with additional "decoding" of type values in error message
|
||||||
|
#define CV_CheckTypeEQ(t1, t2, msg) CV__CHECK(_, EQ, MatType, t1, t2, #t1, #t2, msg)
|
||||||
|
/// Check with additional "decoding" of depth values in error message
|
||||||
|
#define CV_CheckDepthEQ(d1, d2, msg) CV__CHECK(_, EQ, MatDepth, d1, d2, #d1, #d2, msg)
|
||||||
|
|
||||||
|
#define CV_CheckChannelsEQ(c1, c2, msg) CV__CHECK(_, EQ, MatChannels, c1, c2, #c1, #c2, msg)
|
||||||
|
|
||||||
|
/// Example: type == CV_8UC1 || type == CV_8UC3
|
||||||
|
#define CV_CheckType(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatType, t, (test_expr), #t, #test_expr, msg)
|
||||||
|
|
||||||
|
/// Example: depth == CV_32F || depth == CV_64F
|
||||||
|
#define CV_CheckDepth(t, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, MatDepth, t, (test_expr), #t, #test_expr, msg)
|
||||||
|
|
||||||
|
/// Example: v == A || v == B
|
||||||
|
#define CV_Check(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg)
|
||||||
|
|
||||||
|
/// Example: v == true
|
||||||
|
#define CV_CheckTrue(v, msg) CV__CHECK_CUSTOM_TEST(_, true, v, v, #v, "", msg)
|
||||||
|
|
||||||
|
/// Example: v == false
|
||||||
|
#define CV_CheckFalse(v, msg) CV__CHECK_CUSTOM_TEST(_, false, v, (!(v)), #v, "", msg)
|
||||||
|
|
||||||
|
/// Some complex conditions: CV_Check(src2, src2.empty() || (src2.type() == src1.type() && src2.size() == src1.size()), "src2 should have same size/type as src1")
|
||||||
|
// TODO define pretty-printers
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define CV_DbgCheck(v, test_expr, msg) CV__CHECK_CUSTOM_TEST(_, auto, v, (test_expr), #v, #test_expr, msg)
|
||||||
|
#define CV_DbgCheckEQ(v1, v2, msg) CV__CHECK(_, EQ, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_DbgCheckNE(v1, v2, msg) CV__CHECK(_, NE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_DbgCheckLE(v1, v2, msg) CV__CHECK(_, LE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_DbgCheckLT(v1, v2, msg) CV__CHECK(_, LT, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_DbgCheckGE(v1, v2, msg) CV__CHECK(_, GE, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#define CV_DbgCheckGT(v1, v2, msg) CV__CHECK(_, GT, auto, v1, v2, #v1, #v2, msg)
|
||||||
|
#else
|
||||||
|
#define CV_DbgCheck(v, test_expr, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckEQ(v1, v2, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckNE(v1, v2, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckLE(v1, v2, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckLT(v1, v2, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckGE(v1, v2, msg) do { } while (0)
|
||||||
|
#define CV_DbgCheckGT(v1, v2, msg) do { } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
#endif // OPENCV_CORE_CHECK_HPP
|
@ -0,0 +1,48 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifdef __OPENCV_BUILD
|
||||||
|
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "E:\OpenCV\opencv\build\include\opencv2\core.hpp"
|
@ -0,0 +1,763 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CORE_CUDAINL_HPP
|
||||||
|
#define OPENCV_CORE_CUDAINL_HPP
|
||||||
|
|
||||||
|
#include "opencv2/core/cuda.hpp"
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
namespace cv { namespace cuda {
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// GpuMat
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(Allocator* allocator_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{
|
||||||
|
if (rows_ > 0 && cols_ > 0)
|
||||||
|
create(rows_, cols_, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(Size size_, int type_, Allocator* allocator_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{
|
||||||
|
if (size_.height > 0 && size_.width > 0)
|
||||||
|
create(size_.height, size_.width, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: unreachable code using Ninja
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4702)
|
||||||
|
#endif
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{
|
||||||
|
if (rows_ > 0 && cols_ > 0)
|
||||||
|
{
|
||||||
|
create(rows_, cols_, type_);
|
||||||
|
setTo(s_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{
|
||||||
|
if (size_.height > 0 && size_.width > 0)
|
||||||
|
{
|
||||||
|
create(size_.height, size_.width, type_);
|
||||||
|
setTo(s_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(const GpuMat& m)
|
||||||
|
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), allocator(m.allocator)
|
||||||
|
{
|
||||||
|
if (refcount)
|
||||||
|
CV_XADD(refcount, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::GpuMat(InputArray arr, Allocator* allocator_) :
|
||||||
|
flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||||
|
{
|
||||||
|
upload(arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat::~GpuMat()
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat& GpuMat::operator =(const GpuMat& m)
|
||||||
|
{
|
||||||
|
if (this != &m)
|
||||||
|
{
|
||||||
|
GpuMat temp(m);
|
||||||
|
swap(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMat::create(Size size_, int type_)
|
||||||
|
{
|
||||||
|
create(size_.height, size_.width, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMat::swap(GpuMat& b)
|
||||||
|
{
|
||||||
|
std::swap(flags, b.flags);
|
||||||
|
std::swap(rows, b.rows);
|
||||||
|
std::swap(cols, b.cols);
|
||||||
|
std::swap(step, b.step);
|
||||||
|
std::swap(data, b.data);
|
||||||
|
std::swap(datastart, b.datastart);
|
||||||
|
std::swap(dataend, b.dataend);
|
||||||
|
std::swap(refcount, b.refcount);
|
||||||
|
std::swap(allocator, b.allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::clone() const
|
||||||
|
{
|
||||||
|
GpuMat m;
|
||||||
|
copyTo(m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: unreachable code using Ninja
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4702)
|
||||||
|
#endif
|
||||||
|
inline
|
||||||
|
void GpuMat::copyTo(OutputArray dst, InputArray mask) const
|
||||||
|
{
|
||||||
|
copyTo(dst, mask, Stream::Null());
|
||||||
|
}
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat& GpuMat::setTo(Scalar s)
|
||||||
|
{
|
||||||
|
return setTo(s, Stream::Null());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat& GpuMat::setTo(Scalar s, InputArray mask)
|
||||||
|
{
|
||||||
|
return setTo(s, mask, Stream::Null());
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: unreachable code using Ninja
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4702)
|
||||||
|
#endif
|
||||||
|
inline
|
||||||
|
void GpuMat::convertTo(OutputArray dst, int rtype) const
|
||||||
|
{
|
||||||
|
convertTo(dst, rtype, Stream::Null());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const
|
||||||
|
{
|
||||||
|
convertTo(dst, rtype, alpha, beta, Stream::Null());
|
||||||
|
}
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const
|
||||||
|
{
|
||||||
|
convertTo(dst, rtype, alpha, 0.0, stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMat::assignTo(GpuMat& m, int _type) const
|
||||||
|
{
|
||||||
|
if (_type < 0)
|
||||||
|
m = *this;
|
||||||
|
else
|
||||||
|
convertTo(m, _type);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uchar* GpuMat::ptr(int y)
|
||||||
|
{
|
||||||
|
CV_DbgAssert( (unsigned)y < (unsigned)rows );
|
||||||
|
return data + step * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
const uchar* GpuMat::ptr(int y) const
|
||||||
|
{
|
||||||
|
CV_DbgAssert( (unsigned)y < (unsigned)rows );
|
||||||
|
return data + step * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp> inline
|
||||||
|
_Tp* GpuMat::ptr(int y)
|
||||||
|
{
|
||||||
|
return (_Tp*)ptr(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _Tp> inline
|
||||||
|
const _Tp* GpuMat::ptr(int y) const
|
||||||
|
{
|
||||||
|
return (const _Tp*)ptr(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T> inline
|
||||||
|
GpuMat::operator PtrStepSz<T>() const
|
||||||
|
{
|
||||||
|
return PtrStepSz<T>(rows, cols, (T*)data, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T> inline
|
||||||
|
GpuMat::operator PtrStep<T>() const
|
||||||
|
{
|
||||||
|
return PtrStep<T>((T*)data, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::row(int y) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, Range(y, y+1), Range::all());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::col(int x) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, Range::all(), Range(x, x+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::rowRange(int startrow, int endrow) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, Range(startrow, endrow), Range::all());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::rowRange(Range r) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, r, Range::all());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::colRange(int startcol, int endcol) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, Range::all(), Range(startcol, endcol));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::colRange(Range r) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, Range::all(), r);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, rowRange_, colRange_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMat GpuMat::operator ()(Rect roi) const
|
||||||
|
{
|
||||||
|
return GpuMat(*this, roi);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMat::isContinuous() const
|
||||||
|
{
|
||||||
|
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMat::elemSize() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMat::elemSize1() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE1(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int GpuMat::type() const
|
||||||
|
{
|
||||||
|
return CV_MAT_TYPE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int GpuMat::depth() const
|
||||||
|
{
|
||||||
|
return CV_MAT_DEPTH(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int GpuMat::channels() const
|
||||||
|
{
|
||||||
|
return CV_MAT_CN(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMat::step1() const
|
||||||
|
{
|
||||||
|
return step / elemSize1();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
Size GpuMat::size() const
|
||||||
|
{
|
||||||
|
return Size(cols, rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMat::empty() const
|
||||||
|
{
|
||||||
|
return data == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void* GpuMat::cudaPtr() const
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
GpuMat createContinuous(int rows, int cols, int type)
|
||||||
|
{
|
||||||
|
GpuMat m;
|
||||||
|
createContinuous(rows, cols, type, m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void createContinuous(Size size, int type, OutputArray arr)
|
||||||
|
{
|
||||||
|
createContinuous(size.height, size.width, type, arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
GpuMat createContinuous(Size size, int type)
|
||||||
|
{
|
||||||
|
GpuMat m;
|
||||||
|
createContinuous(size, type, m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void ensureSizeIsEnough(Size size, int type, OutputArray arr)
|
||||||
|
{
|
||||||
|
ensureSizeIsEnough(size.height, size.width, type, arr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void swap(GpuMat& a, GpuMat& b)
|
||||||
|
{
|
||||||
|
a.swap(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// GpuMatND
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMatND::GpuMatND() :
|
||||||
|
flags(0), dims(0), data(nullptr), offset(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
GpuMatND::GpuMatND(SizeArray _size, int _type) :
|
||||||
|
flags(0), dims(0), data(nullptr), offset(0)
|
||||||
|
{
|
||||||
|
create(std::move(_size), _type);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void GpuMatND::swap(GpuMatND& m) noexcept
|
||||||
|
{
|
||||||
|
std::swap(*this, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMatND::isContinuous() const
|
||||||
|
{
|
||||||
|
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMatND::isSubmatrix() const
|
||||||
|
{
|
||||||
|
return (flags & Mat::SUBMATRIX_FLAG) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMatND::elemSize() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMatND::elemSize1() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE1(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMatND::empty() const
|
||||||
|
{
|
||||||
|
return data == nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool GpuMatND::external() const
|
||||||
|
{
|
||||||
|
return !empty() && data_.use_count() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uchar* GpuMatND::getDevicePtr() const
|
||||||
|
{
|
||||||
|
return data + offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMatND::total() const
|
||||||
|
{
|
||||||
|
size_t p = 1;
|
||||||
|
for(auto s : size)
|
||||||
|
p *= s;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t GpuMatND::totalMemSize() const
|
||||||
|
{
|
||||||
|
return size[0] * step[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int GpuMatND::type() const
|
||||||
|
{
|
||||||
|
return CV_MAT_TYPE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// HostMem
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::HostMem(AllocType alloc_type_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::HostMem(const HostMem& m)
|
||||||
|
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), alloc_type(m.alloc_type)
|
||||||
|
{
|
||||||
|
if( refcount )
|
||||||
|
CV_XADD(refcount, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||||
|
{
|
||||||
|
if (rows_ > 0 && cols_ > 0)
|
||||||
|
create(rows_, cols_, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::HostMem(Size size_, int type_, AllocType alloc_type_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||||
|
{
|
||||||
|
if (size_.height > 0 && size_.width > 0)
|
||||||
|
create(size_.height, size_.width, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::HostMem(InputArray arr, AllocType alloc_type_)
|
||||||
|
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||||
|
{
|
||||||
|
arr.getMat().copyTo(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem::~HostMem()
|
||||||
|
{
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem& HostMem::operator =(const HostMem& m)
|
||||||
|
{
|
||||||
|
if (this != &m)
|
||||||
|
{
|
||||||
|
HostMem temp(m);
|
||||||
|
swap(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void HostMem::swap(HostMem& b)
|
||||||
|
{
|
||||||
|
std::swap(flags, b.flags);
|
||||||
|
std::swap(rows, b.rows);
|
||||||
|
std::swap(cols, b.cols);
|
||||||
|
std::swap(step, b.step);
|
||||||
|
std::swap(data, b.data);
|
||||||
|
std::swap(datastart, b.datastart);
|
||||||
|
std::swap(dataend, b.dataend);
|
||||||
|
std::swap(refcount, b.refcount);
|
||||||
|
std::swap(alloc_type, b.alloc_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
HostMem HostMem::clone() const
|
||||||
|
{
|
||||||
|
HostMem m(size(), type(), alloc_type);
|
||||||
|
createMatHeader().copyTo(m);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
void HostMem::create(Size size_, int type_)
|
||||||
|
{
|
||||||
|
create(size_.height, size_.width, type_);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
Mat HostMem::createMatHeader() const
|
||||||
|
{
|
||||||
|
return Mat(size(), type(), data, step);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool HostMem::isContinuous() const
|
||||||
|
{
|
||||||
|
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t HostMem::elemSize() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t HostMem::elemSize1() const
|
||||||
|
{
|
||||||
|
return CV_ELEM_SIZE1(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int HostMem::type() const
|
||||||
|
{
|
||||||
|
return CV_MAT_TYPE(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int HostMem::depth() const
|
||||||
|
{
|
||||||
|
return CV_MAT_DEPTH(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int HostMem::channels() const
|
||||||
|
{
|
||||||
|
return CV_MAT_CN(flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t HostMem::step1() const
|
||||||
|
{
|
||||||
|
return step / elemSize1();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
Size HostMem::size() const
|
||||||
|
{
|
||||||
|
return Size(cols, rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool HostMem::empty() const
|
||||||
|
{
|
||||||
|
return data == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
void swap(HostMem& a, HostMem& b)
|
||||||
|
{
|
||||||
|
a.swap(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// Stream
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
inline
|
||||||
|
Stream::Stream(const Ptr<Impl>& impl)
|
||||||
|
: impl_(impl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// Event
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
inline
|
||||||
|
Event::Event(const Ptr<Impl>& impl)
|
||||||
|
: impl_(impl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// Initialization & Info
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
// WARNING: unreachable code using Ninja
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4702)
|
||||||
|
#endif
|
||||||
|
inline
|
||||||
|
bool TargetArchs::has(int major, int minor)
|
||||||
|
{
|
||||||
|
return hasPtx(major, minor) || hasBin(major, minor);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool TargetArchs::hasEqualOrGreater(int major, int minor)
|
||||||
|
{
|
||||||
|
return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
DeviceInfo::DeviceInfo()
|
||||||
|
{
|
||||||
|
device_id_ = getDevice();
|
||||||
|
}
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
inline
|
||||||
|
DeviceInfo::DeviceInfo(int device_id)
|
||||||
|
{
|
||||||
|
CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() );
|
||||||
|
device_id_ = device_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: unreachable code using Ninja
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable: 4702)
|
||||||
|
#endif
|
||||||
|
inline
|
||||||
|
int DeviceInfo::deviceID() const
|
||||||
|
{
|
||||||
|
return device_id_;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t DeviceInfo::freeMemory() const
|
||||||
|
{
|
||||||
|
size_t _totalMemory = 0, _freeMemory = 0;
|
||||||
|
queryMemory(_totalMemory, _freeMemory);
|
||||||
|
return _freeMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
size_t DeviceInfo::totalMemory() const
|
||||||
|
{
|
||||||
|
size_t _totalMemory = 0, _freeMemory = 0;
|
||||||
|
queryMemory(_totalMemory, _freeMemory);
|
||||||
|
return _totalMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool DeviceInfo::supports(FeatureSet feature_set) const
|
||||||
|
{
|
||||||
|
int version = majorVersion() * 10 + minorVersion();
|
||||||
|
return version >= feature_set;
|
||||||
|
}
|
||||||
|
#if defined _MSC_VER && _MSC_VER >= 1920
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
}} // namespace cv { namespace cuda {
|
||||||
|
|
||||||
|
//===================================================================================
|
||||||
|
// Mat
|
||||||
|
//===================================================================================
|
||||||
|
|
||||||
|
namespace cv {
|
||||||
|
|
||||||
|
inline
|
||||||
|
Mat::Mat(const cuda::GpuMat& m)
|
||||||
|
: flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows)
|
||||||
|
{
|
||||||
|
m.download(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#endif // OPENCV_CORE_CUDAINL_HPP
|
@ -0,0 +1,211 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CUDA_DEVICE_BLOCK_HPP
|
||||||
|
#define OPENCV_CUDA_DEVICE_BLOCK_HPP
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @deprecated Use @ref cudev instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
namespace cv { namespace cuda { namespace device
|
||||||
|
{
|
||||||
|
struct Block
|
||||||
|
{
|
||||||
|
static __device__ __forceinline__ unsigned int id()
|
||||||
|
{
|
||||||
|
return blockIdx.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __device__ __forceinline__ unsigned int stride()
|
||||||
|
{
|
||||||
|
return blockDim.x * blockDim.y * blockDim.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __device__ __forceinline__ void sync()
|
||||||
|
{
|
||||||
|
__syncthreads();
|
||||||
|
}
|
||||||
|
|
||||||
|
static __device__ __forceinline__ int flattenedThreadId()
|
||||||
|
{
|
||||||
|
return threadIdx.z * blockDim.x * blockDim.y + threadIdx.y * blockDim.x + threadIdx.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename It, typename T>
|
||||||
|
static __device__ __forceinline__ void fill(It beg, It end, const T& value)
|
||||||
|
{
|
||||||
|
int STRIDE = stride();
|
||||||
|
It t = beg + flattenedThreadId();
|
||||||
|
|
||||||
|
for(; t < end; t += STRIDE)
|
||||||
|
*t = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename OutIt, typename T>
|
||||||
|
static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value)
|
||||||
|
{
|
||||||
|
int STRIDE = stride();
|
||||||
|
int tid = flattenedThreadId();
|
||||||
|
value += tid;
|
||||||
|
|
||||||
|
for(OutIt t = beg + tid; t < end; t += STRIDE, value += STRIDE)
|
||||||
|
*t = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InIt, typename OutIt>
|
||||||
|
static __device__ __forceinline__ void copy(InIt beg, InIt end, OutIt out)
|
||||||
|
{
|
||||||
|
int STRIDE = stride();
|
||||||
|
InIt t = beg + flattenedThreadId();
|
||||||
|
OutIt o = out + (t - beg);
|
||||||
|
|
||||||
|
for(; t < end; t += STRIDE, o += STRIDE)
|
||||||
|
*o = *t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InIt, typename OutIt, class UnOp>
|
||||||
|
static __device__ __forceinline__ void transform(InIt beg, InIt end, OutIt out, UnOp op)
|
||||||
|
{
|
||||||
|
int STRIDE = stride();
|
||||||
|
InIt t = beg + flattenedThreadId();
|
||||||
|
OutIt o = out + (t - beg);
|
||||||
|
|
||||||
|
for(; t < end; t += STRIDE, o += STRIDE)
|
||||||
|
*o = op(*t);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename InIt1, typename InIt2, typename OutIt, class BinOp>
|
||||||
|
static __device__ __forceinline__ void transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op)
|
||||||
|
{
|
||||||
|
int STRIDE = stride();
|
||||||
|
InIt1 t1 = beg1 + flattenedThreadId();
|
||||||
|
InIt2 t2 = beg2 + flattenedThreadId();
|
||||||
|
OutIt o = out + (t1 - beg1);
|
||||||
|
|
||||||
|
for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, o += STRIDE)
|
||||||
|
*o = op(*t1, *t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int CTA_SIZE, typename T, class BinOp>
|
||||||
|
static __device__ __forceinline__ void reduce(volatile T* buffer, BinOp op)
|
||||||
|
{
|
||||||
|
int tid = flattenedThreadId();
|
||||||
|
T val = buffer[tid];
|
||||||
|
|
||||||
|
if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); }
|
||||||
|
|
||||||
|
if (tid < 32)
|
||||||
|
{
|
||||||
|
if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); }
|
||||||
|
if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); }
|
||||||
|
if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); }
|
||||||
|
if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); }
|
||||||
|
if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); }
|
||||||
|
if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int CTA_SIZE, typename T, class BinOp>
|
||||||
|
static __device__ __forceinline__ T reduce(volatile T* buffer, T init, BinOp op)
|
||||||
|
{
|
||||||
|
int tid = flattenedThreadId();
|
||||||
|
T val = buffer[tid] = init;
|
||||||
|
__syncthreads();
|
||||||
|
|
||||||
|
if (CTA_SIZE >= 1024) { if (tid < 512) buffer[tid] = val = op(val, buffer[tid + 512]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 512) { if (tid < 256) buffer[tid] = val = op(val, buffer[tid + 256]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 256) { if (tid < 128) buffer[tid] = val = op(val, buffer[tid + 128]); __syncthreads(); }
|
||||||
|
if (CTA_SIZE >= 128) { if (tid < 64) buffer[tid] = val = op(val, buffer[tid + 64]); __syncthreads(); }
|
||||||
|
|
||||||
|
if (tid < 32)
|
||||||
|
{
|
||||||
|
if (CTA_SIZE >= 64) { buffer[tid] = val = op(val, buffer[tid + 32]); }
|
||||||
|
if (CTA_SIZE >= 32) { buffer[tid] = val = op(val, buffer[tid + 16]); }
|
||||||
|
if (CTA_SIZE >= 16) { buffer[tid] = val = op(val, buffer[tid + 8]); }
|
||||||
|
if (CTA_SIZE >= 8) { buffer[tid] = val = op(val, buffer[tid + 4]); }
|
||||||
|
if (CTA_SIZE >= 4) { buffer[tid] = val = op(val, buffer[tid + 2]); }
|
||||||
|
if (CTA_SIZE >= 2) { buffer[tid] = val = op(val, buffer[tid + 1]); }
|
||||||
|
}
|
||||||
|
__syncthreads();
|
||||||
|
return buffer[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, class BinOp>
|
||||||
|
static __device__ __forceinline__ void reduce_n(T* data, unsigned int n, BinOp op)
|
||||||
|
{
|
||||||
|
int ftid = flattenedThreadId();
|
||||||
|
int sft = stride();
|
||||||
|
|
||||||
|
if (sft < n)
|
||||||
|
{
|
||||||
|
for (unsigned int i = sft + ftid; i < n; i += sft)
|
||||||
|
data[ftid] = op(data[ftid], data[i]);
|
||||||
|
|
||||||
|
__syncthreads();
|
||||||
|
|
||||||
|
n = sft;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (n > 1)
|
||||||
|
{
|
||||||
|
unsigned int half = n/2;
|
||||||
|
|
||||||
|
if (ftid < half)
|
||||||
|
data[ftid] = op(data[ftid], data[n - ftid - 1]);
|
||||||
|
|
||||||
|
__syncthreads();
|
||||||
|
|
||||||
|
n = n - half;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}}}
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#endif /* OPENCV_CUDA_DEVICE_BLOCK_HPP */
|
@ -0,0 +1,722 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CUDA_BORDER_INTERPOLATE_HPP
|
||||||
|
#define OPENCV_CUDA_BORDER_INTERPOLATE_HPP
|
||||||
|
|
||||||
|
#include "saturate_cast.hpp"
|
||||||
|
#include "vec_traits.hpp"
|
||||||
|
#include "vec_math.hpp"
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @deprecated Use @ref cudev instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
namespace cv { namespace cuda { namespace device
|
||||||
|
{
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BrdConstant
|
||||||
|
|
||||||
|
template <typename D> struct BrdRowConstant
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdRowConstant(int width_, const D& val_ = VecTraits<D>::all(0)) : width(width_), val(val_) {}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return x >= 0 ? saturate_cast<D>(data[x]) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return x < width ? saturate_cast<D>(data[x]) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return (x >= 0 && x < width) ? saturate_cast<D>(data[x]) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width;
|
||||||
|
D val;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdColConstant
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdColConstant(int height_, const D& val_ = VecTraits<D>::all(0)) : height(height_), val(val_) {}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return y >= 0 ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return y < height ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return (y >= 0 && y < height) ? saturate_cast<D>(*(const T*)((const char*)data + y * step)) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int height;
|
||||||
|
D val;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdConstant
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BrdConstant(int height_, int width_, const D& val_ = VecTraits<D>::all(0)) : height(height_), width(width_), val(val_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(((const T*)((const uchar*)data + y * step))[x]) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const
|
||||||
|
{
|
||||||
|
return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int height;
|
||||||
|
int width;
|
||||||
|
D val;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BrdReplicate
|
||||||
|
|
||||||
|
template <typename D> struct BrdRowReplicate
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdRowReplicate(int width) : last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdRowReplicate(int width, U) : last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return ::max(x, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return ::min(x, last_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_low(idx_col_high(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_low(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_high(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdColReplicate
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdColReplicate(int height) : last_row(height - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdColReplicate(int height, U) : last_row(height - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return ::max(y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return ::min(y, last_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_low(idx_row_high(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const T*)((const char*)data + idx_row_low(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const T*)((const char*)data + idx_row_high(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const T*)((const char*)data + idx_row(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdReplicate
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BrdReplicate(int height, int width) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdReplicate(int height, int width, U) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return ::max(y, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return ::min(y, last_row);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_low(idx_row_high(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return ::max(x, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return ::min(x, last_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_low(idx_col_high(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(src(idx_row(y), idx_col(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BrdReflect101
|
||||||
|
|
||||||
|
template <typename D> struct BrdRowReflect101
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdRowReflect101(int width) : last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdRowReflect101(int width, U) : last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return ::abs(x) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_low(idx_col_high(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_low(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_high(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdColReflect101
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdColReflect101(int height) : last_row(height - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdColReflect101(int height, U) : last_row(height - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return ::abs(y) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_low(idx_row_high(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdReflect101
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BrdReflect101(int height, int width) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdReflect101(int height, int width, U) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return ::abs(y) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return ::abs(last_row - ::abs(last_row - y)) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_low(idx_row_high(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return ::abs(x) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return ::abs(last_col - ::abs(last_col - x)) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_low(idx_col_high(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(src(idx_row(y), idx_col(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BrdReflect
|
||||||
|
|
||||||
|
template <typename D> struct BrdRowReflect
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdRowReflect(int width) : last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdRowReflect(int width, U) : last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return (::abs(x) - (x < 0)) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return ::abs(last_col - ::abs(last_col - x) + (x > last_col)) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_high(::abs(x) - (x < 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_low(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_high(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdColReflect
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdColReflect(int height) : last_row(height - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdColReflect(int height, U) : last_row(height - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return (::abs(y) - (y < 0)) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return ::abs(last_row - ::abs(last_row - y) + (y > last_row)) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_high(::abs(y) - (y < 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdReflect
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BrdReflect(int height, int width) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdReflect(int height, int width, U) : last_row(height - 1), last_col(width - 1) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return (::abs(y) - (y < 0)) % (last_row + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return /*::abs*/(last_row - ::abs(last_row - y) + (y > last_row)) /*% (last_row + 1)*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_low(idx_row_high(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return (::abs(x) - (x < 0)) % (last_col + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return (last_col - ::abs(last_col - x) + (x > last_col));
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_low(idx_col_high(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(src(idx_row(y), idx_col(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int last_row;
|
||||||
|
int last_col;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BrdWrap
|
||||||
|
|
||||||
|
template <typename D> struct BrdRowWrap
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdRowWrap(int width_) : width(width_) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdRowWrap(int width_, U) : width(width_) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return (x >= 0) * x + (x < 0) * (x - ((x - width + 1) / width) * width);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return (x < width) * x + (x >= width) * (x % width);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_high(idx_col_low(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_low(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col_high(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int x, const T* data) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(data[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int width;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdColWrap
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
explicit __host__ __device__ __forceinline__ BrdColWrap(int height_) : height(height_) {}
|
||||||
|
template <typename U> __host__ __device__ __forceinline__ BrdColWrap(int height_, U) : height(height_) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return (y >= 0) * y + (y < 0) * (y - ((y - height + 1) / height) * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return (y < height) * y + (y >= height) * (y % height);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_high(idx_row_low(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_low(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_low(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at_high(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row_high(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(*(const D*)((const char*)data + idx_row(y) * step));
|
||||||
|
}
|
||||||
|
|
||||||
|
int height;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename D> struct BrdWrap
|
||||||
|
{
|
||||||
|
typedef D result_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BrdWrap(int height_, int width_) :
|
||||||
|
height(height_), width(width_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
template <typename U>
|
||||||
|
__host__ __device__ __forceinline__ BrdWrap(int height_, int width_, U) :
|
||||||
|
height(height_), width(width_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_low(int y) const
|
||||||
|
{
|
||||||
|
return (y >= 0) ? y : (y - ((y - height + 1) / height) * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row_high(int y) const
|
||||||
|
{
|
||||||
|
return (y < height) ? y : (y % height);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_row(int y) const
|
||||||
|
{
|
||||||
|
return idx_row_high(idx_row_low(y));
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_low(int x) const
|
||||||
|
{
|
||||||
|
return (x >= 0) ? x : (x - ((x - width + 1) / width) * width);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col_high(int x) const
|
||||||
|
{
|
||||||
|
return (x < width) ? x : (x % width);
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ int idx_col(int x) const
|
||||||
|
{
|
||||||
|
return idx_col_high(idx_col_low(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T> __device__ __forceinline__ D at(int y, int x, const T* data, size_t step) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(((const T*)((const char*)data + idx_row(y) * step))[idx_col(x)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Ptr2D> __device__ __forceinline__ D at(typename Ptr2D::index_type y, typename Ptr2D::index_type x, const Ptr2D& src) const
|
||||||
|
{
|
||||||
|
return saturate_cast<D>(src(idx_row(y), idx_col(x)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int height;
|
||||||
|
int width;
|
||||||
|
};
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// BorderReader
|
||||||
|
|
||||||
|
template <typename Ptr2D, typename B> struct BorderReader
|
||||||
|
{
|
||||||
|
typedef typename B::result_type elem_type;
|
||||||
|
typedef typename Ptr2D::index_type index_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BorderReader(const Ptr2D& ptr_, const B& b_) : ptr(ptr_), b(b_) {}
|
||||||
|
|
||||||
|
__device__ __forceinline__ elem_type operator ()(index_type y, index_type x) const
|
||||||
|
{
|
||||||
|
return b.at(y, x, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr2D ptr;
|
||||||
|
B b;
|
||||||
|
};
|
||||||
|
|
||||||
|
// under win32 there is some bug with templated types that passed as kernel parameters
|
||||||
|
// with this specialization all works fine
|
||||||
|
template <typename Ptr2D, typename D> struct BorderReader< Ptr2D, BrdConstant<D> >
|
||||||
|
{
|
||||||
|
typedef typename BrdConstant<D>::result_type elem_type;
|
||||||
|
typedef typename Ptr2D::index_type index_type;
|
||||||
|
|
||||||
|
__host__ __device__ __forceinline__ BorderReader(const Ptr2D& src_, const BrdConstant<D>& b) :
|
||||||
|
src(src_), height(b.height), width(b.width), val(b.val)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
__device__ __forceinline__ D operator ()(index_type y, index_type x) const
|
||||||
|
{
|
||||||
|
return (x >= 0 && x < width && y >= 0 && y < height) ? saturate_cast<D>(src(y, x)) : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ptr2D src;
|
||||||
|
int height;
|
||||||
|
int width;
|
||||||
|
D val;
|
||||||
|
};
|
||||||
|
}}} // namespace cv { namespace cuda { namespace cudev
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#endif // OPENCV_CUDA_BORDER_INTERPOLATE_HPP
|
@ -0,0 +1,309 @@
|
|||||||
|
/*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.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// License Agreement
|
||||||
|
// For Open Source Computer Vision Library
|
||||||
|
//
|
||||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||||
|
// 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 the copyright holders 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*/
|
||||||
|
|
||||||
|
#ifndef OPENCV_CUDA_COLOR_HPP
|
||||||
|
#define OPENCV_CUDA_COLOR_HPP
|
||||||
|
|
||||||
|
#include "detail/color_detail.hpp"
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @deprecated Use @ref cudev instead.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! @cond IGNORED
|
||||||
|
|
||||||
|
namespace cv { namespace cuda { namespace device
|
||||||
|
{
|
||||||
|
// All OPENCV_CUDA_IMPLEMENT_*_TRAITS(ColorSpace1_to_ColorSpace2, ...) macros implements
|
||||||
|
// template <typename T> class ColorSpace1_to_ColorSpace2_traits
|
||||||
|
// {
|
||||||
|
// typedef ... functor_type;
|
||||||
|
// static __host__ __device__ functor_type create_functor();
|
||||||
|
// };
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgr_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS(bgra_to_rgba, 4, 4, 2)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr555, 3, 0, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgr_to_bgr565, 3, 0, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr555, 3, 2, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgb_to_bgr565, 3, 2, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr555, 4, 0, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(bgra_to_bgr565, 4, 0, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr555, 4, 2, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS(rgba_to_bgr565, 4, 2, 6)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2RGB5x5_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgb, 3, 2, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgb, 3, 2, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgr, 3, 0, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgr, 3, 0, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_rgba, 4, 2, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_rgba, 4, 2, 6)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr555_to_bgra, 4, 0, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS(bgr565_to_bgra, 4, 0, 6)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB5x52RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgr, 3)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS(gray_to_bgra, 4)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr555, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS(gray_to_bgr565, 6)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_GRAY2RGB5x5_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr555_to_gray, 5)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS(bgr565_to_gray, 6)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB5x52GRAY_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgb_to_gray, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgr_to_gray, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(rgba_to_gray, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS(bgra_to_gray, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2GRAY_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgb_to_yuv4, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(rgba_to_yuv4, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgr_to_yuv4, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS(bgra_to_yuv4, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2YUV_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_rgba, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgr, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS(yuv4_to_bgra, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_YUV2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgb_to_YCrCb4, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(rgba_to_YCrCb4, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgr_to_YCrCb4, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS(bgra_to_YCrCb4, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2YCrCb_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_rgba, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgr, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS(YCrCb4_to_bgra, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_YCrCb2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgb_to_xyz4, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(rgba_to_xyz4, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgr_to_xyz4, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS(bgra_to_xyz4, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2XYZ_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_rgba, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgr, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS(xyz4_to_bgra, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_XYZ2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgb_to_hsv4, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(rgba_to_hsv4, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgr_to_hsv4, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS(bgra_to_hsv4, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2HSV_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_rgba, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgr, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS(hsv4_to_bgra, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_HSV2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgb_to_hls4, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(rgba_to_hls4, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgr_to_hls4, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS(bgra_to_hls4, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2HLS_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgb, 3, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_rgba, 3, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgb, 4, 3, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_rgba, 4, 4, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgr, 3, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls_to_bgra, 3, 4, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgr, 4, 3, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS(hls4_to_bgra, 4, 4, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_HLS2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab, 3, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab, 4, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgb_to_lab4, 3, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(rgba_to_lab4, 4, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab, 3, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab, 4, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgr_to_lab4, 3, 4, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(bgra_to_lab4, 4, 4, true, 0)
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab, 3, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab, 4, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgb_to_lab4, 3, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lrgba_to_lab4, 4, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab, 3, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab, 4, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgr_to_lab4, 3, 4, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS(lbgra_to_lab4, 4, 4, false, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2Lab_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgb, 3, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgb, 4, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_rgba, 3, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_rgba, 4, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgr, 3, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgr, 4, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_bgra, 3, 4, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_bgra, 4, 4, true, 0)
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgb, 3, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgb, 4, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lrgba, 3, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lrgba, 4, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgr, 3, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgr, 4, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab_to_lbgra, 3, 4, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS(lab4_to_lbgra, 4, 4, false, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_Lab2RGB_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv, 3, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv, 4, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgb_to_luv4, 3, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(rgba_to_luv4, 4, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv, 3, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv, 4, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgr_to_luv4, 3, 4, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(bgra_to_luv4, 4, 4, true, 0)
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv, 3, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv, 4, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgb_to_luv4, 3, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lrgba_to_luv4, 4, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv, 3, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv, 4, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgr_to_luv4, 3, 4, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS(lbgra_to_luv4, 4, 4, false, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_RGB2Luv_TRAITS
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgb, 3, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgb, 4, 3, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_rgba, 3, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_rgba, 4, 4, true, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgr, 3, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgr, 4, 3, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_bgra, 3, 4, true, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_bgra, 4, 4, true, 0)
|
||||||
|
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgb, 3, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgb, 4, 3, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lrgba, 3, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lrgba, 4, 4, false, 2)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgr, 3, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgr, 4, 3, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv_to_lbgra, 3, 4, false, 0)
|
||||||
|
OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS(luv4_to_lbgra, 4, 4, false, 0)
|
||||||
|
|
||||||
|
#undef OPENCV_CUDA_IMPLEMENT_Luv2RGB_TRAITS
|
||||||
|
}}} // namespace cv { namespace cuda { namespace cudev
|
||||||
|
|
||||||
|
//! @endcond
|
||||||
|
|
||||||
|
#endif // OPENCV_CUDA_COLOR_HPP
|