Let $F:U_q\times U_Q\times I\to \mathbb R$ be smooth, and suppose
\begin{align*}
\det\left(\frac{\partial^2 F}{\partial q_i\partial Q_j}\right)_{1\le i,j\le n}\ne 0
\end{align*}
on the region under consideration. Then the equations
\begin{align*}
p_i=\frac{\partial F}{\partial q_i},\qquad P_i=-\frac{\partial F}{\partial Q_i}
\end{align*}
define, after possibly shrinking $U_q$ and $U_Q$, a local change of variables between open subsets of phase space with coordinates $(q,p)$ and $(Q,P)$. This transformation is canonical, and the transformed Hamiltonian is
\begin{align*}
K(Q,P,t)=H(q,p,t)+\frac{\partial F}{\partial t}(q,Q,t),
\end{align*}
with $(q,p)$ expressed in terms of $(Q,P,t)$.