EXHIBIT 23.1 CONSENT OF INDEPENDENT REGISTERED PUBLIC ACCOUNTING FIRM We consent to the incorporation by reference in this Annual Report (Form 10-K) of Cognex Corporation of our report dated March 1, 2006, with respect to the consolidated financial statements of Cognex Corporation and our report dated March 1, 2006 with respect to Cognex Corporation management's assessment of the effectiveness of internal control over financial reporting and the effectiveness of internal control over financial reporting of Cognex Corporation, included in the 2005 Annual Report to Shareholders of Cognex Corporation. Our audits also included the financial statement schedule of Cognex Corporation listed in Item 15(a). This schedule is the responsibility of Cognex Corporation's management. Our responsibility is to express an opinion based on our audits. In our opinion, as to which the date is March 1, 2006, the financial statement schedule referred to above, when considered in relation to the basic financial statements taken as a whole, presents fairly in all material respects the information set forth therein. We consent to the incorporation by reference in the Registration Statements on Form S-8 (File Nos. 33-81150, 333-04621, 333-02151, 333-60807, 33-32815, 333-44824, 333-68158, 333-96961, 333-100709, and 333-126787) of Cognex Corporation of our report dated March 1, 2006, with respect to the consolidated financial statements of Cognex Corporation incorporated herein by reference, our report dated March 1, 2006 with respect to Cognex Corporation management's assessment of the effectiveness of internal control over financial reporting and the effectiveness of internal control over financial reporting of Cognex Corporation incorporated herein by reference, and our report included in the preceding paragraph with respect to the financial statement schedule of Cognex Corporation included in this Annual Report (Form 10-K) of Cognex Corporation. /s/ Ernst & Young LLP Boston, Massachusetts March 1, 2006