  We present a lattice-QCD determination of the elastic isospin-$1/2$ $S$-wave
and $P$-wave $K\pi$ scattering amplitudes as a function of the center-of-mass
energy using L\"uscher's method. We perform global fits of $K$-matrix
parametrizations to the finite-volume energy spectra for all irreducible
representations with total momenta up to $\sqrt{3}\frac{2\pi}{L}$; this
includes irreps that mix the $S$- and $P$-waves. Several different
parametrizations for the energy dependence of the $K$-matrix are considered. We
also determine the positions of the nearest poles in the scattering amplitudes,
which correspond to the broad $\kappa$ resonance in the $S$-wave and the narrow
$K^*(892)$ resonance in the $P$-wave. Our calculations are performed with $2+1$
dynamical clover fermions for two different pion masses of $317.2(2.2)$ and
$175.9(1.8)$ MeV. Our preferred $S$-wave parametrization is based on a
conformal map and includes an Adler zero; for the $P$-wave we use a standard
pole parametrization including Blatt-Weisskopf barrier factors. The $S$-wave
$\kappa$-resonance pole positions are found to be $\left[0.86(12) -
0.309(50)\,i\right]\:{\rm GeV}$ at the heavier pion mass and $\left[0.499(55)-
0.379(66)\,i\right]\:{\rm GeV}$ at the lighter pion mass. The $P$-wave
$K^*$-resonance pole positions are found to be $\left[ 0.8951(64) -
0.00250(21)\,i \right]\:{\rm GeV}$ at the heavier pion mass and
$\left[0.8718(82) - 0.0130(11)\,i\right]\:{\rm GeV}$ at the lighter pion mass,
which corresponds to couplings of $g_{K^* K\pi}=5.02(26)$ and $g_{K^*
K\pi}=4.99(22)$, respectively.
