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;
SAFEARRAYBOUND BoundOutput;
BoundOutput.cElements = nPoints;
BoundOutput.lLbound = 0;
output = SafeArrayCreate(VT_I4, 1, &BoundOutput);
int* pdata1;
SafeArrayAccessData(output, (void**)&pdata1);
for (int i = 0; i < nPoints; i++)
pdata1[i] = src_pts[i];
SafeArrayUnaccessData(output);
SAFEARRAY* output2;
SAFEARRAYBOUND BoundOutput2;
BoundOutput2.cElements = nPoints;
BoundOutput2.lLbound = 0;
output2 = SafeArrayCreate(VT_I4, 1, &BoundOutput2);
int* pdata2;
SafeArrayAccessData(output2, (void**)&pdata2);
for (int i = 0; i < nPoints; i++)
pdata2[i] = dst_pts[i];
SafeArrayUnaccessData(output2);
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;
}
댓글