SAFEARRAY* IntArrayToSafeArray(int pts[], int nPoints)
{
SAFEARRAY* safearray;
SAFEARRAYBOUND BoundOutput;
BoundOutput.cElements = nPoints;
BoundOutput.lLbound = 0;
safearray = SafeArrayCreate(VT_I4, 1, &BoundOutput);
int* pdata;
SafeArrayAccessData(safearray, (void**)&pdata);
for (int i = 0; i < nPoints; i++)
pdata[i] = pts[i];
SafeArrayUnaccessData(safearray);
return safearray;
}
int getPerspectiveTransform(char* src_img_file, char* dst_img_file)
{
int result;
const int nPoints = 8;
_bstr_t src_img_file2(src_img_file);
_bstr_t dst_img_file2(dst_img_file);
int src_pts[8] = { 10, 25, 120, 790, 2200, 750, 2275, 10 };
int dst_pts[8] = { 10, 25, 10, 790, 2275, 790, 2275, 25 };
SAFEARRAY* output;
SAFEARRAY* output2;
output = IntArrayToSafeArray(src_pts, nPoints);
output2 = IntArrayToSafeArray(dst_pts, nPoints);
OpenCVInterface* ocv = NULL;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_OpenCV, NULL, CLSCTX_INPROC_SERVER, IID_OpenCVInterface, reinterpret_cast<void**>(&ocv));
if (SUCCEEDED(hr))
{
result = ocv->getPerspectiveTransform(src_img_file2, dst_img_file2, output, output2);
result = 1;
}
else
result = 0;
return result;
}
댓글