Patch-clamp is the main technique for measuring electrical properties of individual cells. Since its discovery in 1976 by Neher and Sakmann, patch clamp has been instrumental in broadening our understanding of the fundamental properties of ion channels and synapses in neurons. The conventional patch-clamp method requires manual, precise positioning of a glass micropipette against the cell membrane of a visually-identified target neuron. Subsequently, a tight "giga-seal" connection between the pipette and the cell membrane is established, and suction is applied to establish the whole-cell patch configuration to perform electrophysiological recordings. This procedure is repeated manually for each individual cell making it labor-intensive and time-consuming. Here we describe the development of a new automatic patch-clamp system for brain slices, which integrates all steps of the patch-clamp process: image acquisition through a microscope, computer vision-based identification of a patch pipette and fluorescently-labeled neurons, micromanipulator control, and automated patching. We validated our system in brain slices from wild-type and transgenic mice expressing Channelrhodopsin-2 under the Thy1 promoter (line 18), or injected with a herpes simplex virus (HSV) expressing archaerhodopsin ArchT. Our computer vision-based algorithm makes the fluorescent cell detection and targeting user-independent. Compared to manual patching, our system is superior in both success rate and average trial duration. It provides more reliable trial-to-trial control of the patching process and improves reproducibility of experiments.