compiled opencv copy to another host
If the end result would be entirely contained in a directory somewhere you could simply archive that directory after the installation on one machine and restore it on the new machine. It does work for some apps.

But after going through the Ubuntu 18.04: How to install OpenCV procedure and peeking into the makefiles I believe this wouldn't be applicable to OpenCV: its artefacts are spread in various places on a Ubuntu system.

But I think it's possible to significantly reduce the installation time by skipping the actual build process, which appears to be the bulk of the process. From the above referenced procedure (which I'll also use in describing the proposed solution):


  This process may take 30 minutes or longer, so go for a nice walk if
  you are able.


I'll re-use the referenced procedure for describing the proposal, with a few tweaks (I'd like to think that the tweaks would easily be portable to future/similar versions of the procedure):

In the initial installation:


after the build completes but before the Installing and verifying OpenCV step insert:

Step 4a: save the pre-built official OpenCV source tree to S3

Follow Copying from s3 to EC2 instance instructions for S3 access setup, then run:

tar cvfz pre_built_opencv.tgz opencv*
s3cmd put pre_built_opencv.tgz s3://&lt;bucket_name&gt;


Optional: you can remove the local archive copy now:

rm pre_built_opencv.tgz



In the subsequent installations:


replace Step #2: Download the official OpenCV source with:

Step #2: Extract the pre-built official OpenCV source tree from S3

Follow Copying from s3 to EC2 instance instructions for S3 access setup, then run:

cd ~
s3cmd get s3://&lt;bucket_name&gt;/pre_built_opencv.tgz pre_built_opencv.tgz
tar xvzf pre_built_opencv.tgz


Optional: you can remove the local archive copy now:

rm pre_built_opencv.tgz

in Step #4: Configure and compile OpenCV for Ubuntu 18.04:


skip the Configure OpenCV with CMake section
replace the Compiling OpenCV on Ubuntu 18.04 section with:

Enter the pre-built OpenCV build directory

cd ~/opencv/build




I didn't run it myself, but I think it should work, at least for VMs of the same type. 

I'd 1st try the same even for different VM types. If that doesn't work then I'd re-run the initial installation for them, using a different archive filename.