In this case, the following trick also works: Dividing both the numerator and the denominator by $\cos^4 x$, we can use the substitution $ t = \tan x$ to obtain
\begin{align*}
\int_{0}^{\frac{\pi}{2}} \frac{dx}{(a^2 \cos^2 x + b^2 \sin^2 x)^2}
&= \int_{0}^{\frac{\pi}{2}} \frac{1 + \tan^2 x}{(a^2 + b^2 \tan^2 x)^2} \sec^2 x \, dx \\
&= \int_{0}^{\infty} \frac{1 + t^2}{(a^2 + b^2 t^2)^2} \, dt \\
&= \frac{1}{a^2}\int_{0}^{\infty} \left( \frac{1}{a^2 + b^2 t^2} + \frac{(a^2 - b^2) t^2}{(a^2 + b^2 t^2)^2} \right) \, dt.
\end{align*}
The first one can be evaluated as follows: Let $bt = a \tan\varphi$. Then
$$ \int_{0}^{\infty} \frac{dt}{a^2 + b^2 t^2} = \frac{1}{ab} \int_{0}^{\frac{\pi}{2}} d\varphi = \frac{\pi}{2ab}. $$
For the second one, we perform the integration by parts:
\begin{align*}
\int_{0}^{\infty} \frac{t^2}{(a^2 + b^2 t^2)^2} \, dt
&= \left[ - \frac{1}{b^2}\frac{1}{a^2 + b^2 t^2} \cdot \frac{t}{2} \right]_{0}^{\infty} + \int_{0}^{\infty} \frac{1}{2b^2}\frac{dt}{a^2 + b^2 t^2} \\
&= \frac{1}{2b^2} \int_{0}^{\infty} \frac{dt}{a^2 + b^2 t^2} \\
&= \frac{\pi}{4ab^3}.
\end{align*}
Putting together, the answer is
$$ \frac{(a^2 + b^2)\pi}{4(ab)^3}. $$