Engineering drawings, including hand written-based or computer-based, are frequently utilized; across various industries such as electronic, mechanical, oil, and gas. Extracting, recognizing, and interpreting a circuit can provide easier debugging and further information. This paper proposes a new method to identify primary gates and their connected lines in electrical circuits to generate hardware description languages (HDLs), automatically. This method comprises three main phases. First, applying morphological and logical/arithmetic operations eliminate all lines except gates. Second, the resulted image including logical gates is examined to recognize primary gates using an object detector. For this purpose, the proposed method recognizes all objects using connected component technique and graph theory. According to the shape feature, the type of gate is identified. Finally, a cost-free model is suggested for detecting input and output lines for each gate. Then, the recognized gates and elements in the circuit are used to generate an HDL code. Experimental results verify the promising accuracy of the proposed method.