apps: add Win32 friendly opencv_version app

Improve experience of launching app from explorer:
- application just flash (open/close) the console window
Suggested Win32 application flavor additionally shows MessageBox
and waits for User interaction.
pull/11734/head
Alexander Alekhin 7 years ago
parent 0614ee3f95
commit 95360a5539
  1. 33
      apps/version/CMakeLists.txt
  2. 50
      apps/version/opencv_version.cpp

@ -1,19 +1,13 @@
SET(OPENCV_APPLICATION_DEPS opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs opencv_videoio)
set(OPENCV_APPLICATION_DEPS opencv_core)
ocv_check_dependencies(${OPENCV_APPLICATION_DEPS})
if(NOT OCV_DEPENDENCIES_FOUND)
return()
endif()
project(opencv_version)
set(the_target opencv_version)
ocv_target_include_directories(${the_target} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" "${OpenCV_SOURCE_DIR}/include/opencv")
ocv_target_include_modules_recurse(${the_target} ${OPENCV_APPLICATION_DEPS})
file(GLOB SRCS *.cpp)
ocv_add_executable(${the_target} ${SRCS})
ocv_add_executable(${the_target} opencv_version.cpp)
ocv_target_link_libraries(${the_target} ${OPENCV_APPLICATION_DEPS})
set_target_properties(${the_target} PROPERTIES
@ -30,3 +24,26 @@ if(INSTALL_CREATE_DISTRIB)
else()
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs)
endif()
if(WIN32)
project(opencv_version_win32)
set(the_target opencv_version_win32)
ocv_target_include_modules_recurse(${the_target} ${OPENCV_APPLICATION_DEPS})
ocv_add_executable(${the_target} opencv_version.cpp)
ocv_target_link_libraries(${the_target} ${OPENCV_APPLICATION_DEPS})
target_compile_definitions(${the_target} PRIVATE "OPENCV_WIN32_API=1")
set_target_properties(${the_target} PROPERTIES
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
RUNTIME_OUTPUT_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}
OUTPUT_NAME "opencv_version_win32")
set_target_properties(${the_target} PROPERTIES FOLDER "applications")
if(INSTALL_CREATE_DISTRIB)
if(BUILD_SHARED_LIBS)
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} CONFIGURATIONS Release COMPONENT libs)
endif()
else()
install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs)
endif()
endif()

@ -9,6 +9,31 @@
#include <opencv2/core/opencl/opencl_info.hpp>
#ifdef OPENCV_WIN32_API
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
static void dumpHWFeatures(bool showAll = false)
{
std::cout << "OpenCV's HW features list:" << std::endl;
int count = 0;
for (int i = 0; i < CV_HARDWARE_MAX_FEATURE; i++)
{
cv::String name = cv::getHardwareFeatureName(i);
if (name.empty())
continue;
bool enabled = cv::checkHardwareSupport(i);
if (enabled)
count++;
if (enabled || showAll)
{
printf(" ID=%3d (%s) -> %s\n", i, name.c_str(), enabled ? "ON" : "N/A");
}
}
std::cout << "Total available: " << count << std::endl;
}
int main(int argc, const char** argv)
{
CV_TRACE_FUNCTION();
@ -16,6 +41,7 @@ int main(int argc, const char** argv)
CV_TRACE_ARG_VALUE(argv0, "argv0", argv[0]);
CV_TRACE_ARG_VALUE(argv1, "argv1", argv[1]);
#ifndef OPENCV_WIN32_API
cv::CommandLineParser parser(argc, argv,
"{ help h usage ? | | show this help message }"
"{ verbose v | | show build configuration log }"
@ -45,24 +71,14 @@ int main(int argc, const char** argv)
if (parser.has("hw"))
{
bool showAll = parser.get<bool>("hw");
std::cout << "OpenCV's HW features list:" << std::endl;
int count = 0;
for (int i = 0; i < CV_HARDWARE_MAX_FEATURE; i++)
{
cv::String name = cv::getHardwareFeatureName(i);
if (name.empty())
continue;
bool enabled = cv::checkHardwareSupport(i);
if (enabled)
count++;
if (enabled || showAll)
{
printf(" ID=%3d (%s) -> %s\n", i, name.c_str(), enabled ? "ON" : "N/A");
}
}
std::cout << "Total available: " << count << std::endl;
dumpHWFeatures(parser.get<bool>("hw"));
}
#else
std::cout << cv::getBuildInformation().c_str() << std::endl;
cv::dumpOpenCLInformation();
dumpHWFeatures();
MessageBoxA(NULL, "Check console window output", "OpenCV(" CV_VERSION ")", MB_ICONINFORMATION | MB_OK);
#endif
return 0;
}

Loading…
Cancel
Save