August 6, 1998



Cognex Corporation
One Vision Drive
Natick, MA  01760

Ladies and Gentlemen:

         We  are  general  counsel  to  Cognex   Corporation,   a  Massachusetts
corporation  (the  "Company"),  and as such  counsel  we are  familiar  with the
corporate  proceedings  taken in  connection  with the adoption of the Company's
1998 Stock Incentive Plan and 1997 Stock Option Plan for Non-Employee  Directors
(collectively the "Plans"). We are also familiar with the registration statement
on Form S-8 to which a copy of this opinion will be attached as an exhibit.

         As such counsel, we have examined the corporate records of the Company,
including the Restated Articles of Organization, By-laws, stock records, minutes
of meetings of its Board of Directors and  stockholders and such other documents
as we have deemed necessary as a basis for the opinions herein expressed.

         Based  upon  the   foregoing,   and   having   regard  for  such  legal
considerations as we deem relevant, we are of the opinion that:

         1.       The Company is duly organized and validly existing under the 
laws of the Commonwealth of Massachusetts;

         2. The Company has  authorized  the issuance of  120,000,000  shares of
common  stock  having a par  value of $.002  per  share  and  400,000  shares of
preferred stock having a par value of $.01 per share.

         3. The shares of common stock issuable pursuant to the Plans, when sold
in accordance  with the terms thereof,  will be legally  issued,  fully paid and
non-assessable.





         We hereby  consent to the  filing of this  opinion as an exhibit to the
Registration  Statement on Form S-8 and to the reference to us under the caption
"Interests of Named Experts and Counsel" in the Registration Statement.


                                                Very truly yours,

                                                /s/Hutchins, Wheeler & Dittmar

                                                HUTCHINS, WHEELER & DITTMAR
                                                A Professional Corporation

AJM/LXD/332069-1