// File: /workspace/github_cpp_makefile_star2_O2/manikandan5[P]Image-Matching-Stitching-Warping/./Homography.h
// Function: getProjection(Image const&, Image const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void getProjection(const Image& I1,const Image& I2,const string& name)
{	
	SiftDescriptorMap mapping;
	int count = Image::MatchSIFT(I1,I2,mapping);
	
	if(count <4)
	{
		cout<<" Image "<<name<<" cannot be formed due to insufficient Sift matchings"<<endl;
		return ;
	}
	
	assert(count >= 4);
	// We need 4 points to get Projection
	
	//Figure out to find N
	int N = 10000;
		
	int inliners = -1;
	CImg<double> bestProjection;
	for(int i = 0;i<N;++i)
	{
		CImg<double> projection = linearSystemSolver(mapping);
		int numberOfInliners = getInliners(projection,mapping);
		if(numberOfInliners > inliners)
		{
			inliners = numberOfInliners;
			bestProjection = projection;
			//cout<<inliners<<endl;
		}
	}
	
	assert(inliners > 0);		
	//cout<<"Inliners = "<<inliners<<" , size = "<<mapping.size()<<endl;
	
	//Converting 8 X 1 matrix to 3 X 3 matrix
	CImg<double> actualProjection(3,3);
	actualProjection(0,0) = bestProjection(0,0);
	actualProjection(1,0) = bestProjection(0,1);
	actualProjection(2,0) = bestProjection(0,2);
	actualProjection(0,1) = bestProjection(0,3);
	actualProjection(1,1) = bestProjection(0,4);
	actualProjection(2,1) = bestProjection(0,5);
	actualProjection(0,2) = bestProjection(0,6);
	actualProjection(1,2) = bestProjection(0,7);
	actualProjection(2,2) = 1;
		
	projectiveTransform(I1,actualProjection,name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
xorl %ecx, %ecx
callq 0x7226
cmpl $0x3, %eax
jg 0x5420
movq 0x8abd3(%rip), %rdi     # 0x8ffc0
leaq 0x5060c(%rip), %rsi     # 0x55a00
callq 0x4520
movq %rax, %rdi
movq %rbx, %rsi
callq 0x44a0
leaq 0x505fd(%rip), %rsi     # 0x55a08
movq %rax, %rdi
callq 0x4520
movq %rax, %rdi
callq 0x4200
jmp 0x557b
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x50(%rsp), %r15
andq $0x0, 0x18(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movb $0x0, 0x10(%r15)
pushq $-0x1
popq %r14
movl $0x2710, %ebx           # imm = 0x2710
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
subl $0x1, %ebx
jb 0x548c
movq %r12, %rdi
movq %r13, %rsi
callq 0x50a9
movq %r12, %rdi
movq %r13, %rsi
callq 0x52af
cmpl %r14d, %eax
jle 0x5482
movl %eax, %ebp
movq %r15, %rdi
movq %r12, %rsi
callq 0x2ad88
movl %ebp, %r14d
movq %r12, %rdi
callq 0x6c96
jmp 0x5452
testl %r14d, %r14d
jle 0x5594
leaq 0x10(%rsp), %rdi
pushq $0x3
popq %rdx
pushq $0x1
popq %rcx
movl %edx, %esi
movl %ecx, %r8d
callq 0x6caa
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
movq 0x68(%rsp), %rcx
movsd (%rcx), %xmm0
leaq 0x10(%rsp), %rsi
movq 0x18(%rsi), %rax
movsd %xmm0, (%rax)
movl 0x50(%rsp), %r9d
movsd (%rcx,%r9,8), %xmm0
movsd %xmm0, 0x8(%rax)
leal (%r9,%r9), %r8d
movsd (%rcx,%r8,8), %xmm0
movsd %xmm0, 0x10(%rax)
leal (%r9,%r9,2), %r8d
movsd (%rcx,%r8,8), %xmm0
movl (%rsi), %r10d
movsd %xmm0, (%rax,%r10,8)
leal (,%r9,4), %r8d
movsd (%rcx,%r8,8), %xmm0
leal 0x1(%r10), %r8d
movsd %xmm0, (%rax,%r8,8)
leal (%r9,%r9,4), %r8d
movsd (%rcx,%r8,8), %xmm0
leal 0x2(%r10), %r8d
movsd %xmm0, (%rax,%r8,8)
imull $0x6, %r9d, %r8d
movsd (%rcx,%r8,8), %xmm0
leal (%r10,%r10), %r8d
movsd %xmm0, (%rax,%r8,8)
imull $0x7, %r9d, %r9d
movsd (%rcx,%r9,8), %xmm0
movsd %xmm0, 0x8(%rax,%r8,8)
leal 0x2(,%r10,2), %ecx
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
movq %r8, (%rax,%rcx,8)
callq 0x4c5c
leaq 0x10(%rsp), %rdi
callq 0x6c96
leaq 0x50(%rsp), %rdi
callq 0x6c96
leaq 0x30(%rsp), %rdi
callq 0x7506
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x504f2(%rip), %rdi     # 0x55a8d
leaq 0x5049b(%rip), %rsi     # 0x55a3d
leaq 0x504a3(%rip), %rcx     # 0x55a4c
movl $0xb1, %edx
callq 0x4330
jmp 0x55bc
jmp 0x55cb
movq %rax, %rbx
jmp 0x55d8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6c96
jmp 0x55ce
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x6c96
leaq 0x30(%rsp), %rdi
callq 0x7506
movq %rbx, %rdi
callq 0x4950