We present a method to derive macroscopic fluid-dynamic models from microscopic car-following models via a coarse-graining procedure. The method is first demonstrated for the optimal velocity model. The derived macroscopic model consists of a conservation equation and a momentum equation, and the latter contains a relaxation term, an anticipation term, and a diffusion term. Properties of the resulting macroscopic model are compared with those of the optimal velocity model through numerical simulations, and reasonable agreement is found although there are deviations in the quantitative level. The derivation is also extended to general car-following models.