


'''simple docstring'''




from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve





def 				a_							(    lowercase				,    lowercase				,    lowercase     )      ->np.ndarray:






				'''simple docstring'''

				__lowerCamelCase		:   Tuple           =       np.stack((horizontal_flow, vertical_flow)				,    2     )

				# Create a grid of all pixel coordinates and subtract the flow to get the
				# target pixels coordinates
				__lowerCamelCase		:   Dict           =       np.stack(
				    np.meshgrid(np.arange(0				,    image.shape[1]     )				,    np.arange(0				,    image.shape[0]     )     )				,    2     )
				__lowerCamelCase		:   int           =       np.round(grid - flow     ).astype(np.intaa     )

				# Find the locations outside of the original image
				__lowerCamelCase		:   int           =       (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]     ))
				__lowerCamelCase		:   int           =       0

				__lowerCamelCase		:   List[Any]           =       image[grid[:, :, 1], grid[:, :, 0]]

				# Set pixels at invalid locations to 0
				__lowerCamelCase		:   int           =       0

				return warped





def 				a_							(    lowercase				,    lowercase				,    lowercase				,    lowercase = None				,    )      ->tuple[np.ndarray, np.ndarray]:






				'''simple docstring'''

				if alpha is None:
								__lowerCamelCase		:   Dict           =       0.1

				# Initialize flow
				__lowerCamelCase		:   Optional[int]           =       np.zeros_like(lowercase     )
				__lowerCamelCase		:   List[Any]           =       np.zeros_like(lowercase     )

				# Prepare kernels for the calculation of the derivatives and the average velocity
				__lowerCamelCase		:   Union[str, Any]           =       np.array([[-1, 1], [-1, 1]]     ) * 0.2_5
				__lowerCamelCase		:   Union[str, Any]           =       np.array([[-1, -1], [1, 1]]     ) * 0.2_5
				__lowerCamelCase		:   Optional[int]           =       np.array([[1, 1], [1, 1]]     ) * 0.2_5
				__lowerCamelCase		:   Optional[int]           =       np.array(
				    [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]     )

				# Iteratively refine the flow
				for _ in range(lowercase     ):
								__lowerCamelCase		:   Optional[int]           =       warp(lowercase				,    lowercase				,    lowercase     )
								__lowerCamelCase		:   List[str]           =       convolve(lowercase				,    lowercase     ) + convolve(lowercase				,    lowercase     )
								__lowerCamelCase		:   List[Any]           =       convolve(lowercase				,    lowercase     ) + convolve(lowercase				,    lowercase     )
								__lowerCamelCase		:   int           =       convolve(lowercase				,    lowercase     ) + convolve(lowercase				,    -kernel_t     )

								__lowerCamelCase		:   int           =       convolve(lowercase				,    lowercase     )
								__lowerCamelCase		:   Dict           =       convolve(lowercase				,    lowercase     )

								# This updates the flow as proposed in the paper (Step 12)
								__lowerCamelCase		:   Tuple           =       (
								    derivative_x * avg_horizontal_velocity
								    + derivative_y * avg_vertical_velocity
								    + derivative_t
								)
								__lowerCamelCase		:   Optional[int]           =       update / (alpha**2 + derivative_x**2 + derivative_y**2)

								__lowerCamelCase		:   Optional[int]           =       avg_horizontal_velocity - derivative_x * update
								__lowerCamelCase		:   Union[str, Any]           =       avg_vertical_velocity - derivative_y * update

				return horizontal_flow, vertical_flow


if __name__ == "__main__":
				import doctest

				doctest.testmod()









'''simple docstring'''




import requests

try:
				from django.contrib.auth import authenticate, login
				from django.shortcuts import redirect, render
except ImportError:
				__lowercase	:   Dict   		=					print





def 				a_							(    lowercase     )      ->Any:






				'''simple docstring'''

				__lowerCamelCase		:   str           =       "secretKey"
				__lowerCamelCase		:   Optional[Any]           =       "https://www.google.com/recaptcha/api/siteverify"

				# when method is not POST, direct user to login page
				if request.method != "POST":
								return render(lowercase				,    "login.html"     )

				# from the frontend, get username, password, and client_key
				__lowerCamelCase		:   str           =       request.POST.get("username"     )
				__lowerCamelCase		:   Dict           =       request.POST.get("password"     )
				__lowerCamelCase		:   List[str]           =       request.POST.get("g-recaptcha-response"     )

				# post recaptcha response to Google's recaptcha api
				__lowerCamelCase		:   str           =       requests.post(lowercase				,    data={"secret": secret_key, "response": client_key}     )
				# if the recaptcha api verified our keys
				if response.json().get("success"				,    lowercase     ):
								# authenticate the user
								__lowerCamelCase		:   List[Any]           =       authenticate(lowercase				,    username=lowercase				,    password=lowercase     )
								if user_in_database:
												login(lowercase				,    lowercase     )
												return redirect("/your-webpage"     )
				return render(lowercase				,    "login.html"     )





