是否有适用于 Windows Phone 8 和 Windows 8 的 OpenCV 图形库的支持。我在 Google 上进行了搜索,但没有找到任何与 OpenCV 相关的资源来连接 Windows Phone 8 / Windows 8。如果你们中的任何人知道更多关于这个请帮助我,并提供一些链接到图书馆。
3 回答
这是我从 OpenCV 团队获得的最新信息。
OpenCV 开发团队正在为 Windows RT 开发端口。这是 WinRT 的当前开发分支(https://github.com/asmorkalov/opencv/tree/winrt)。您可以使用 Visual Studio Express for Windows 8 和 Platform SDK 为 ARM 构建它。
Open Visual Studio development console.
Setup environment for cross compilation by command "C:\Program Files(x86)\Microsoft
Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat"
cd <opencv_source_dir>/platforms/winrt/
run scripts/cmake_winrt.cmd
run ninja
或者,您可以使用 nmake 代替 ninja。您需要编辑 cmake_winrt.cmd 并将项目生成器从 -GNinja 更改为 -G "NMake Makefiles"。现在只支持库的算法部分,没有 tbb,没有 UI,没有视频 IO。
请从以下给出的 URL 中查看更多详细信息。 http://answers.opencv.org/question/9847/opencv-for-windows-8-tablet/?answer=9851#post-id-9851
通过 windows-8,我猜你的意思是 winRT ?AFAIK,winRT 没有官方端口。例如,您需要将其编译为 Win8 Store DLL,以便您可以从 Win8 Store Application 中引用它。
直接从opencv-core开始,然后一一添加你需要的lib,因为所有组件都无法编译(比如opencv-highgui高度依赖Windows API,不完全兼容Win8 Store Apps )。
您还需要自己编写一些 OpenCV 使用的 Win32 方法,这些方法不能从 Win8 应用程序访问,例如 GetSystemInfo()、GetTempPathA()、GetTempFileNameA() 以及与线程本地存储 (TLS) 相关的所有方法。
通过将 opencv_core、opencv_imgproc 和 zlib 编译为 3 个单独的静态库,我已经能够在 WinRT 中使用一小部分 OpenCV。我已经添加了另一个,称为 opencv_winrt,它只包含以下两个文件:
opencv_winrt.h
#pragma once
#include "combaseapi.h"
void WINAPI GetSystemInfo(
_Out_ LPSYSTEM_INFO lpSystemInfo
);
DWORD WINAPI GetTempPathA(
_In_ DWORD nBufferLength,
_Out_ char* lpBuffer
);
UINT WINAPI GetTempFileNameA(
_In_ const char* lpPathName,
_In_ const char* lpPrefixString,
_In_ UINT uUnique,
_Out_ char* lpTempFileName
);
DWORD WINAPI TlsAlloc();
BOOL WINAPI TlsFree(
_In_ DWORD dwTlsIndex
);
LPVOID WINAPI TlsGetValue(
_In_ DWORD dwTlsIndex
);
BOOL WINAPI TlsSetValue(
_In_ DWORD dwTlsIndex,
_In_opt_ LPVOID lpTlsValue
);
void WINAPI TlsShutdown();
# define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)
opencv_winrt.cpp
#include "opencv_winrt.h"
#include <vector>
#include <set>
#include <mutex>
#include "assert.h"
void WINAPI GetSystemInfo(LPSYSTEM_INFO lpSystemInfo)
{
GetNativeSystemInfo(lpSystemInfo);
}
DWORD WINAPI GetTempPathA(DWORD nBufferLength, char* lpBuffer)
{
return 0;
}
UINT WINAPI GetTempFileNameA(const char* lpPathName, const char* lpPrefixString, UINT uUnique, char* lpTempFileName)
{
return 0;
}
// Thread local storage.
typedef std::vector<void*> ThreadLocalData;
static __declspec(thread) ThreadLocalData* currentThreadData = nullptr;
static std::set<ThreadLocalData*> allThreadData;
static DWORD nextTlsIndex = 0;
static std::vector<DWORD> freeTlsIndices;
static std::mutex tlsAllocationLock;
DWORD WINAPI TlsAlloc()
{
std::lock_guard<std::mutex> lock(tlsAllocationLock);
// Can we reuse a previously freed TLS slot?
if (!freeTlsIndices.empty())
{
DWORD result = freeTlsIndices.back();
freeTlsIndices.pop_back();
return result;
}
// Allocate a new TLS slot.
return nextTlsIndex++;
}
_Use_decl_annotations_ BOOL WINAPI TlsFree(DWORD dwTlsIndex)
{
std::lock_guard<std::mutex> lock(tlsAllocationLock);
assert(dwTlsIndex < nextTlsIndex);
assert(find(freeTlsIndices.begin(), freeTlsIndices.end(), dwTlsIndex) == freeTlsIndices.end());
// Store this slot for reuse by TlsAlloc.
try
{
freeTlsIndices.push_back(dwTlsIndex);
}
catch (...)
{
return false;
}
// Zero the value for all threads that might be using this now freed slot.
for each (auto threadData in allThreadData)
{
if (threadData->size() > dwTlsIndex)
{
threadData->at(dwTlsIndex) = nullptr;
}
}
return true;
}
_Use_decl_annotations_ LPVOID WINAPI TlsGetValue(DWORD dwTlsIndex)
{
ThreadLocalData* threadData = currentThreadData;
if (threadData && threadData->size() > dwTlsIndex)
{
// Return the value of an allocated TLS slot.
return threadData->at(dwTlsIndex);
}
else
{
// Default value for unallocated slots.
return nullptr;
}
}
_Use_decl_annotations_ BOOL WINAPI TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue)
{
ThreadLocalData* threadData = currentThreadData;
if (!threadData)
{
// First time allocation of TLS data for this thread.
try
{
threadData = new ThreadLocalData(dwTlsIndex + 1, nullptr);
std::lock_guard<std::mutex> lock(tlsAllocationLock);
allThreadData.insert(threadData);
currentThreadData = threadData;
}
catch (...)
{
if (threadData)
delete threadData;
return false;
}
}
else if (threadData->size() <= dwTlsIndex)
{
// This thread already has a TLS data block, but it must be expanded to fit the specified slot.
try
{
std::lock_guard<std::mutex> lock(tlsAllocationLock);
threadData->resize(dwTlsIndex + 1, nullptr);
}
catch (...)
{
return false;
}
}
// Store the new value for this slot.
threadData->at(dwTlsIndex) = lpTlsValue;
return true;
}
// Called at thread exit to clean up TLS allocations.
void WINAPI TlsShutdown()
{
ThreadLocalData* threadData = currentThreadData;
if (threadData)
{
{
std::lock_guard<std::mutex> lock(tlsAllocationLock);
allThreadData.erase(threadData);
}
currentThreadData = nullptr;
delete threadData;
}
}
我修改了文件 cvconfig.h:我已经注释掉了每个#define,除了 PACKAGE* 和 VERSION,我在最后添加了#include "opencv_winrt.h"。
只是一个提示 - OpenCV 有一个名为EmguCV
( http://www.emgu.com/wiki/index.php/Main_Page ) 的 C# 包装器,通过查看论坛帖子,我发现有一些活动可以在 Windows 上使用它8 但很难说它现在是否有效,因为声称问题的帖子已经很老了。我建议你试一试,看看这个 C# 包装器是否能够在 Windows Phone 8 上运行,我认为它绝对应该在 Windows 8 上运行。