// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %rdx, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
xorl %ecx, %ecx
callq 0x8bfe
cmpl $0x3, %eax
jg 0x63ce
movq 0xa1c51(%rip), %rdi     # 0xa7fb8
leaq 0x69712(%rip), %rsi     # 0x6fa80
movl $0x7, %edx
callq 0x45b0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xa1c32(%rip), %rdi     # 0xa7fb8
callq 0x45b0
movq %rax, %rbx
leaq 0x696f3(%rip), %rsi     # 0x6fa88
movl $0x34, %edx
movq %rax, %rdi
callq 0x45b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4530
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4050
movq %rax, %rdi
callq 0x4380
jmp 0x6571
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x30(%rsp), %r15
movq $0x0, 0x18(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, (%r15)
movb $0x0, 0x10(%r15)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x2710, %ebx           # imm = 0x2710
movq %rsp, %r12
leaq 0x50(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x5f65
movq %r12, %rdi
movq %r13, %rsi
callq 0x6206
cmpl %r14d, %eax
jle 0x6442
movl %eax, %ebp
movq 0x18(%rsp), %rsi
movl (%rsp), %edx
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %r8d
movl 0xc(%rsp), %r9d
movq %r15, %rdi
callq 0xb880
movl %ebp, %r14d
cmpb $0x0, 0x10(%rsp)
jne 0x6458
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6458
callq 0x4690
decl %ebx
jne 0x6404
testl %r14d, %r14d
jle 0x658a
movq %rsp, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x8666
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rcx
movsd (%rcx), %xmm0
movq %rsp, %rsi
movq 0x18(%rsi), %rax
movsd %xmm0, (%rax)
movl 0x30(%rsp), %r10d
movsd (%rcx,%r10,8), %xmm0
movsd %xmm0, 0x8(%rax)
leal (%r10,%r10), %r8d
movsd (%rcx,%r8,8), %xmm0
movsd %xmm0, 0x10(%rax)
leal (%r10,%r10,2), %r9d
movsd (%rcx,%r9,8), %xmm0
movl (%rsi), %r11d
movsd %xmm0, (%rax,%r11,8)
leal (,%r10,4), %r9d
movsd (%rcx,%r9,8), %xmm0
leal 0x1(%r11), %r9d
movsd %xmm0, (%rax,%r9,8)
leal (%r10,%r10,4), %r9d
movsd (%rcx,%r9,8), %xmm0
leal 0x2(%r11), %r9d
movsd %xmm0, (%rax,%r9,8)
leal (%r8,%r8,2), %r8d
movsd (%rcx,%r8,8), %xmm0
leal (%r11,%r11), %r8d
movsd %xmm0, (%rax,%r8,8)
leal (,%r10,8), %r9d
subl %r10d, %r9d
movsd (%rcx,%r9,8), %xmm0
movsd %xmm0, 0x8(%rax,%r8,8)
leal 0x2(,%r11,2), %ecx
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
movq %r8, (%rax,%rcx,8)
callq 0x5a8c
cmpb $0x0, 0x10(%rsp)
jne 0x655b
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x655b
callq 0x4690
cmpb $0x0, 0x40(%rsp)
jne 0x6571
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x6571
callq 0x4690
leaq 0x50(%rsp), %rdi
callq 0x8fce
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6957c(%rip), %rdi     # 0x6fb0d
leaq 0x69525(%rip), %rsi     # 0x6fabd
leaq 0x6952d(%rip), %rcx     # 0x6facc
movl $0xb1, %edx
callq 0x4340
jmp 0x65b2
jmp 0x65cd
movq %rax, %rbx
jmp 0x65e6
movq %rax, %rbx
cmpb $0x0, 0x10(%rsp)
jne 0x65d0
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x65d0
callq 0x4690
jmp 0x65d0
movq %rax, %rbx
cmpb $0x0, 0x40(%rsp)
jne 0x65e6
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x65e6
callq 0x4690
leaq 0x50(%rsp), %rdi
callq 0x8fce
movq %rbx, %rdi
callq 0x4960