Video Stabilization - using estimateGlobalMotionLeastSquares opencv 2.4.7 - c

I am a newbie about Video Stabilization field. Now I am researching about it.
I'm coding a small video stabilization demo. But I am stuck in some problems
I use the function "estimateGlobalMotionLeastSquares" in OpenCV to estimate global motion
But it doesn't work
Here is my code:
CvPoint2D32f p0, p1;
vector<Point2f,allocator<Point2f>> ax, by;
ax.push_back(Point2f(2,2));
by.push_back(Point2f(3,2));
Mat t = estimateGlobalMotionLeastSquares(ax,by,AFFINE,0);
For example: I create 2 variables p0,p1 as parameter for the function "
estimateGlobalMotionLeastSquares" and I want to estimate global motion "t".
But when I complied, the error is as:
1>VS_OpenCVDlg.obj : error LNK2001: unresolved external symbol "class cv::Mat __cdecl cv::videostab::estimateGlobalMotionLeastSquares(class std::vector,class std::allocator > > const &,class std::vector,class std::allocator > > const &,int,float *)" (?estimateGlobalMotionLeastSquares#videostab#cv##YA?AVMat#2#ABV?$vector#V?$Point_#M#cv##V?$allocator#V?$Point_#M#cv###std###std##0HPAM#Z)
1>F:\Research\Workspace\VS_OpenCV\Debug\VS_OpenCV.exe : fatal error LNK1120: 1 unresolved externals
Please help me to fix this!!!
Can you give me some examples about that function it?

Try to include the proper file :
#include "opencv2/videostab/videostab.hpp"
And change your code to :
CvPoint2D32f p0, p1;
vector<Point2f,allocator<Point2f>> ax, by;
ax.push_back(Point2f(2,2));
ax.push_back(Point2f(2,3));
ax.push_back(Point2f(2,4));
by.push_back(Point2f(3,2));
by.push_back(Point2f(3,3));
by.push_back(Point2f(3,4));
Mat t = videostab::estimateGlobalMotionLeastSquares(ax,by,3,0);

Related

C++/WinRT: MCVC doesn't linking event callback

I'm trying to use Desktop Capture API in c++ project.
Here is initialisation of frame pool:
ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi() {
//
// <neccessary stuff for d3d device and capture item creation>
//
framePool = winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::CreateFreeThreaded(d3dDevice2,
winrt::Windows::Graphics::DirectX::DirectXPixelFormat::B8G8R8A8UIntNormalized,
2, item.Size());
framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived);
captureSession = framePool.CreateCaptureSession(item);
captureSession.StartCapture();
}
and here is ScreenGrabWinCaptureApi::OnFrameArrived definition:
void
ScreenGrabWinCaptureApi::OnFrameArrived(const winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool &sender,
const winrt::Windows::Foundation::IInspectable &) {
// <some buisness logic>
}
I'm trying to build this, and code seems OK to compiler, but linkage fails on framePool.FrameArrived(&ScreenGrabWinCaptureApi::OnFrameArrived); call with
error LNK2019: unresolved external symbol "public: __cdecl winrt::Windows::Foundation::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable>::TypedEventHandler<struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool,struct winrt::Windows::Foundation::IInspectable><void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &)>(void (__cdecl ScreenGrabWinCaptureApi::)(struct winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const &,struct winrt::Windows::Foundation::IInspectable const &))" (??$?0P8ScreenGrabWinCaptureApi##EAAXAEBUDirect3D11CaptureFramePool#Capture#Graphics#Windows#winrt##AEBUIInspectable#Foundation#45##Z#?$TypedEventHandler#UDirect3D11CaptureFramePool#Capture#Graphics#Windows#winrt##UIInspectable#Foundation#45##Foundation#Windows#winrt##QEAA#P8ScreenGrabWinCaptureApi##EAAXAEBUDirect3D11CaptureFramePool#Capture#Graphics#23#AEBUIInspectable#123##Z#Z) referenced in function "public: __cdecl ScreenGrabWinCaptureApi::ScreenGrabWinCaptureApi(void)" (??0ScreenGrabWinCaptureApi##QEAA#XZ)
I've tried all the way of reinterpret/static casts, introducing variable with method reference, replacing method with clojure, but nothing works. Anybody knows what is reason and how to make this running?
As Simon Mourier said in the comments, I've forgotten to include header to TypedEventHandler. My code works after insertion of the corresponding include:
#include "winrt/Windows.Foundation.h"

VS linker can't find PsGetProcessWow64Process

I am trying to compile one driver in VS, but it shows -
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol __imp__PsGetProcessWow64Process#4 referenced in function _GetProcessModule#8 Garhal C:\Users\Raitis\source\repos\GarHal_CSGO\Garhal\memory.obj 1
Quickly enough, I found a place, where this PsGetProcessWow64Process is being used https://prnt.sc/uffavf
But it is defined, and it's even an official ntos.h function. Just pressing F12 on it finds it easily - https://prnt.sc/uffbjg
Screenshot from error list - https://prnt.sc/uffc6t
The problem is that this in undocumented functions and the linker is having a hard time finding where is the function to put a pointer to it in the generated binary, so first include ntifs.h before ntddk.h like this
#include <ntifs.h>
#include <ntddk.h>
it must be before ntddk or you will get weird errors
then add this line :
NTKERNELAPI PVOID PsGetProcessWow64Process(__in PEPROCESS Process);
which is the signature of the function and now you are ready to call that function
another way to get it is using function pointers and resolving it at run time
#include <ntddk.h>
typedef struct _PEB32 {
UCHAR InheritedAddressSpace;
UCHAR ReadImageFileExecOptions;
UCHAR BeingDebugged;
UCHAR Spare;
ULONG Mutant;
ULONG ImageBaseAddress;
ULONG/*PPEB_LDR_DATA32*/ Ldr;
} PEB32, *PPEB32;
typedef PPEB32 (NTAPI * pfn_PsGetProcessWow64Process) (PEPROCESS Process);
pfn_PsGetProcessWow64Process PsGetProcessWow64Process = NULL;
RtlInitUnicodeString (&usFunctionName, L"PsGetProcessWow64Process");
PsGetProcessWow64Process = (pfn_PsGetProcessWow64Process) (SIZE_T)MmGetSystemRoutineAddress (&usFunctionName);
pPEB32 = PsGetProcessWow64Process (pEProcess);

Assigning complex values in gsl

I am trying to use GSL for complex numbers, complex vectors and complex matrices in my project. I am using VS2010 and I added the address of library in Configuration Properties>C/C++>General>Additional Include Directories. But I have a stupid problem. As far as I understood, I can not use = to assign two gsl_complex, gsl_vector_complex or gsl_matrix_complex to each other.
For vectors I have to use gsl_vector_complex_set and for matrices gsl_matrix_complex_set. But for gsl_complex, I only found GSL_SET_COMPLEX in which I should give the real and imaginary parts seperatly as 2 arguments:
GSL_SET_COMPLEX (zp, real, imaginary)
In my code I have such function:
gsl_complex cmx, cmx2;
void vector_complex_exp(gsl_vector_complex *v)
{
for (i = 0; i < v->size; i++)
{
gsl_vector_complex_set(v, i, gsl_complex_exp(gsl_vector_complex_get(v, i)));
}
}
Using this, I get following errors:
error LNK1120: 2 Unresolved external references.
error LNK2001: Unresolved external symbol "_hypot".
error LNK2001: Unresolved external symbol "_log1p".
error LNK2001: Unresolved external symbol "_log1p".
I didn't understand the reason behind these errors. But I rewrite my code like this:
void vector_complex_exp(gsl_vector_complex *v)
{
for (i = 0; i < v->size; i++)
{
cmx = gsl_vector_complex_get(v, i);
//cmx2 = gsl_complex_exp(cmx);
gsl_vector_complex_set(v, i, cmx2);
}
}
Here when the second line in for is commented, there's no error. But when I uncomment it I get the following:
error LNK1120: 2 non-resolved external references.
error LNK2001: Unresolved external symbol "_log1p".
error LNK2019: Reference to non-resolved external symbol "_hypot" in function "_gsl_complex_div".
error LNK2019: Reference to non-resolved external symbol "_log1p" in function "_gsl_complex_logabs".
I don't have any _gsl_complex_div or _gsl_complex_logabs function in my code. So I am pretty sure that the problem is with assignment here. But I can not use GSL_SET_COMPLEX here too.
Can someone help me with this? Is there really no way to assign a value to gsl_complex directly?
It would be better if you published all your code here, therefore, I immediately used this code from the lowest of the examples of the GSL. I made some small changes:
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
int main(void)
{
double data[] = { -1.0, 1.0, -1.0, 1.0,
-8.0, 4.0, -2.0, 1.0,
27.0, 9.0, 3.0, 1.0,
64.0, 16.0, 4.0, 1.0 };
gsl_matrix_view m
= gsl_matrix_view_array(data, 4, 4);
gsl_vector_complex *eval = gsl_vector_complex_alloc(4);
gsl_matrix_complex *evec = gsl_matrix_complex_alloc(4, 4);
gsl_eigen_nonsymmv_workspace * w = gsl_eigen_nonsymmv_alloc(4);
gsl_eigen_nonsymmv(&m.matrix, eval, evec, w);
gsl_eigen_nonsymmv_free(w);
gsl_eigen_nonsymmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);
{
int i, j;
for (i = 0; i < 4; i++)
{
gsl_complex eval_i
= gsl_vector_complex_get(eval, i);
gsl_vector_complex_view evec_i
= gsl_matrix_complex_column(evec, i);
printf("\n eigenvalue = %g + %gi\n",
GSL_REAL(eval_i), GSL_IMAG(eval_i));
printf(" eigenvector = \n");
for (j = 0; j < 4; ++j)
{
gsl_complex z =
gsl_vector_complex_get(&evec_i.vector, j);
printf(" %g + %gi\n", GSL_REAL(z), GSL_IMAG(z));
}
}
}
gsl_vector_complex_free(eval);
gsl_matrix_complex_free(evec);
system("pause");
return 0;
}
Output of this code:
(from the red arrow and below there is a mismatch with the expected output in the GSL example)
To get my output, you need to IDE (I use Visual Studio 2015):
into "your_application" Property pages -> Configuration Properties -> VC++ Directories -> (right pane)in line Executable Directories type: C:\Users\ ...(your GSL build directory path)... \gsl\Release;$(ExecutablePath)
ibid. in line Include Directories type: C:\Users\ ...(your GSL build directory path)... \gsl;$(IncludePath)
ibid. in line Library Directories type: C:\Users\ ...(your GSL build directory path)... \gsl\Release;$(LibraryPath)
Below, in the left pane, select C/C++ -> Peprocessor -> (right pane) in line Preprocessor Defenition type: WIN32;_DEBUG;_CONSOLE;GSL_DLL;%(PreprocessorDefinitions) (I use Debug mode, created empty console application). Save settings (press "Apply" and "OK" buttons)
Copy and put into Debug directories of your application project folder gsl.dll and gslcblas.dll from C:\Users\ ...(your GSL build directory path)... \gsl\Release directory
Buld your application and run it
NOTE!: In the beginning it is best to rebuild GSL with your compiler for the target application - then the work will be guaranteed.
Good luck!

link error in gsl_complex_mul

I have started using gsl recenltly in a huge old C project. I have managed to add the libraries by adding the location in my system in Properties>C/C++>General>Additional Include Directories.
In my code, I am also including the following:
#include "gsl/gsl_matrix.h"
#include "gsl/gsl_matrix_complex_double.h"
#include "gsl/gsl_matrix_complex_float.h"
#include "gsl/gsl_matrix_complex_long_double.h"
#include "gsl/gsl_math.h"
#include "gsl/gsl_spmatrix.h"
#include "gsl/gsl_complex.h"
#include "gsl/gsl_complex_math.h"
#include "gsl/gsl_inline.h"
#include "gsl/gsl_complex.h"
I can now use most functions of gsl. but in the fowllowing function:
void vector_complex_mul_elements(gsl_vector_complex *v1, gsl_vector_complex *v2)
{
gsl_complex cpx1, cpx2, cpx3;
GSL_SET_COMPLEX(&cpx1, 0, 0);
GSL_SET_COMPLEX(&cpx2, 0, 0);
GSL_SET_COMPLEX(&cpx3, 0, 0);
if(v1->size != v2->size)
{
printf("Error: Lenght of arrays do not match.\n");
return;
}
for(i=0; i < v1->size; i++)
{
cpx1 = gsl_vector_complex_get(v1, i);
cpx2 = gsl_vector_complex_get(v2, i);
//cpx3 = gsl_complex_mul(cpx1 , cpx2);
gsl_vector_complex_set(v1, i, cpx3);
}
}
When I uncomment the line:
cpx3 = gsl_complex_mul(cpx1 , cpx2);
I get the following errors:
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK2001: Unresolved external symbol "_hypot".
Error LNK1120: 2 unresolved external references.
I have already tried writing it like:
gsl_vector_complex_set(v1, i, gsl_complex_mul(cpx1 , cpx2));
Then I get these errors:
Error LNK2019: Reference to unresolved external symbol "_log1p" in function "_gsl_complex_logabs".
Error LNK2019: Reference to unresolved external symbol "_hypot" in function "_gsl_complex_div".
Error LNK2001: Unresolved external symbol "_log1p".
Error LNK1120: 2 unresolved external references.
Is this a only a linking problem or the way I am using it is wrong?
These (lop1p and hypot) functions are in the standard maths library. Are you including math.h and linking to it (-lm)? As per the GSL documentation.
It seems to me that you are wrong linked GSL library.
Try to rebuild GSL as a dll and relink it, as I showed you in your other post.

Open .mat files in C

I'm trying to write a C script able to open .mat files. The .mat files were written in Matlab 2015b 64-bit version. I'm using Visual Studio 2010 to compile the code. Here it is:
#include <stdio.h> /*Std library*/
#include "..\matlablib\mat.h" /*provided by MathWorks*/
int main(){
MATFile * pMF;
printf("Abrindo arquivo .mat...\n"); /*check (1)*/
pMF = matOpen("teste.mat","r");
printf("Arquivo .mat aberto.\n"); /*check (2)*/
getch();
}
As I compile this, I get the following message error:
matread.obj : error LNK2019: unresolved external symbol _matOpen
referenced in function _main
matread.exe : fatal error LNK1120: 1 unresolved externals
Have anyone had a similar problem before?
Thanks in advance,
Porto

Resources