// File: /workspace/github_cpp_makefile_star2_O1/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 0x8c5c
cmpl $0x3, %eax
jg 0x63bf
movq 0xa6c60(%rip), %rdi     # 0xacfb8
leaq 0x6e1f1(%rip), %rsi     # 0x74550
movl $0x7, %edx
callq 0x45a0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xa6c41(%rip), %rdi     # 0xacfb8
callq 0x45a0
movq %rax, %rbx
leaq 0x6e1d2(%rip), %rsi     # 0x74558
movl $0x34, %edx
movq %rax, %rdi
callq 0x45a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x4520
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4050
movq %rax, %rdi
callq 0x4370
jmp 0x6562
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 0x5f55
movq %r12, %rdi
movq %r13, %rsi
callq 0x61f7
cmpl %r14d, %eax
jle 0x6433
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 0xb8ee
movl %ebp, %r14d
cmpb $0x0, 0x10(%rsp)
jne 0x6449
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6449
callq 0x4680
decl %ebx
jne 0x63f5
testl %r14d, %r14d
jle 0x657b
movq %rsp, %rdi
movl $0x3, %esi
movl $0x3, %edx
movl $0x1, %ecx
movl $0x1, %r8d
callq 0x86d2
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 0x5a7c
cmpb $0x0, 0x10(%rsp)
jne 0x654c
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x654c
callq 0x4680
cmpb $0x0, 0x40(%rsp)
jne 0x6562
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x6562
callq 0x4680
leaq 0x50(%rsp), %rdi
callq 0x9046
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6e05b(%rip), %rdi     # 0x745dd
leaq 0x6e004(%rip), %rsi     # 0x7458d
leaq 0x6e00c(%rip), %rcx     # 0x7459c
movl $0xb1, %edx
callq 0x4340
jmp 0x65a3
jmp 0x65be
movq %rax, %rbx
jmp 0x65d7
movq %rax, %rbx
cmpb $0x0, 0x10(%rsp)
jne 0x65c1
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x65c1
callq 0x4680
jmp 0x65c1
movq %rax, %rbx
cmpb $0x0, 0x40(%rsp)
jne 0x65d7
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x65d7
callq 0x4680
leaq 0x50(%rsp), %rdi
callq 0x9046
movq %rbx, %rdi
callq 0x4950