Py2exe可执行文件在其他计算机上

时间:2017-09-27 09:12:17

标签: python-2.7 opencv numpy

我用openCV创建了一个python程序,可以在视频中创建运动热图。

我已经成功地将我的python程序编译为.exe,它在我的电脑上完美运行。

但是当我尝试在其他电脑上运行它时,它会在第49行崩溃,并显示以下错误信息

Traceback (most recent call last):
File "Heatmap.py", line 128, in <module>
File "Heatmap.py", line 49, in Heatmap
File "numpy\core\fromnumeric.pyc", line 2720, in size
IndexError: tuple index out of range

这是我的计划:

import Tkinter
import tkFileDialog
import cv2
import numpy as np
import os
import sys
import time
from progress.bar import Bar


class Motion:


    def __init__(self):
        print("Welcome to Heat-map generator pls. Chose Capture file and save directory")

        root = Tkinter.Tk()

        root.filename = tkFileDialog.askopenfilename(initialdir="/", title="Select Video file, !! Recomended file size = 1920*1080 !!",filetypes=(("mp4 files", "*.mp4"), ("avi files", "*.avi"), ("all files", "*.*")))

        root.saveDirectory = tkFileDialog.askdirectory(title = "Select folder to save Heatmap in")


        # input file name of video
        self.inname =  root.filename
        print (str("Capture File: " + self.inname))
        # file name to save
        self.outdir = root.saveDirectory
        print (str("Save directory: "+ self.outdir))

        self.cap = cv2.VideoCapture(self.inname)

        root.destroy()



    def Heatmap(self):



        SizeVal = 0.2

        Heatmap = cv2.VideoCapture()

        totframes = self.cap.get(cv2.CAP_PROP_FRAME_COUNT)

        ret, orig_image = self.cap.read()

        width = np.size(orig_image, 1)

        height = np.size(orig_image, 0)

        # make accumulator image of the same size
        accumulator = np.zeros((height, width), np.float32)  # 32 bit accumulator

        fourcc = cv2.VideoWriter_fourcc('D','I','V','X')

        mp4Out = cv2.VideoWriter(str(self.outdir + "/Movement heatmap.mp4"), fourcc, 25.0, (width, height))

        fgbg = cv2.createBackgroundSubtractorMOG2(history=120,varThreshold=200, detectShadows=False)

        cv2.namedWindow("Heatmap",flags=cv2.WINDOW_NORMAL)

        bar = Bar(" Processing",suffix='%(percent)d%%', max=int(totframes))

        print ("Pres 'q' to abort program")

        for i in range (int(totframes)):


            ret, frame = self.cap.read()  # image is an array of array of [R,G,B] values

            if not ret:

                break

            fgmask = fgbg.apply(frame)

            accumulator = accumulator + fgmask

            ab = cv2.convertScaleAbs(255 - np.array(accumulator, 'uint8'))

                # only get reasonable high values, above mean
            ret, acc_thresh = cv2.threshold(ab, ab.mean(), 500, cv2.THRESH_TOZERO)

                # make a color map
            acc_col = cv2.applyColorMap(acc_thresh, cv2.COLORMAP_JET)

                # add to original frame
            backg = cv2.addWeighted(np.array(acc_col, "uint8"), 0.20, frame, 0.80, 1)

            HeatMaprs = cv2.resize(backg,None,fx=SizeVal,fy=SizeVal, interpolation=cv2.INTER_AREA)
            #acc_colrs = cv2.resize(acc_col, None, fx=SizeVal, fy=SizeVal, interpolation=cv2.INTER_AREA)
            #fgmaskrs = cv2.resize(fgmask, None, fx=self.SizeVal, fy=self.SizeVal, interpolation=cv2.INTER_AREA)
            cv2.imshow("Heatmap",HeatMaprs)

            Heatmap = backg

            mp4Out.write(Heatmap)

            bar.next()

            if (cv2.waitKey(1)&0xFF == ord('q')):

                break

        bar.finish()

        cv2.imwrite(str(self.outdir + "/Movement heatmap.jpg"), Heatmap)
        print ("Heatmap.jpg created")
        mp4Out.release()
        print ("Heatmap.mp4 created")
        self.cap.release()
        print ("Files saved to save folder")
        cv2.destroyAllWindows()






# ==================
# MAIN ENTRY POINT
# ==================

if __name__ == "__main__":
    motionVid = Motion()
    motionVid.Heatmap()

这是我的设置文件:

from distutils.core import setup
import os
import sys
import shutil
import py2exe
import numpy
import cv2
import time
from progress.bar import Bar



setup(script_args=['py2exe'],
    name='Heat map generator',
    version='1.1',
    console=['Heatmap.py'],

    options={
        'py2exe':{

            'compressed': True,

            'bundle_files': 3,

            'includes':['os','sys','cv2','numpy','progress.bar','time'],

            'excludes':[
                        'Carbon', 'Carbon.Files', 'Numeric', '__svn_version__',
                        '_curses', '_dummy_thread', '_imp', '_scproxy', '_sysconfigdata', '_thread',
                        'backports.ssl_match_hostname', 'builtins', 'certifi', 'code_generators.genapi',
                        'code_generators.numpy_api', 'compat.long', 'configparser', 'copyreg', 'core.abs',
                        'core.max', 'core.min', 'core.round', 'dummy.Process', 'fcompiler.FCompiler',
                        'fcompiler.has_f90_header', 'fcompiler.is_f_file', 'genapi', 'importlib.machinery',
                        'nose', 'nose.plugins', 'nose.plugins.base', 'nose.plugins.builtin', 'nose.plugins.errorclass',
                        'nose.util', 'numarray', 'numpy._build_utils.apple_accelerate', 'numpy.amax', 'numpy.amin',
                        'numpy.array', 'numpy.bool_', 'numpy.compat.asbytes', 'numpy.compat.asbytes_nested',
                        'numpy.compat.asstr', 'numpy.compat.basestring', 'numpy.compat.bytes', 'numpy.compat.integer_types',
                        'numpy.compat.is_pathlib_path', 'numpy.compat.isfileobj', 'numpy.compat.long',
                        'numpy.compat.npy_load_module', 'numpy.compat.open_latin1', 'numpy.compat.unicode',
                        'numpy.core.Inf', 'numpy.core.absolute', 'numpy.core.add', 'numpy.core.all', 'numpy.core.amax',
                        'numpy.core.amin', 'numpy.core.any', 'numpy.core.arange', 'numpy.core.around', 'numpy.core.array',
                        'numpy.core.array_repr', 'numpy.core.asanyarray', 'numpy.core.asarray', 'numpy.core.atleast_1d',
                        'numpy.core.atleast_2d', 'numpy.core.atleast_3d', 'numpy.core.bitwise_and', 'numpy.core.bitwise_or',
                        'numpy.core.bitwise_xor', 'numpy.core.broadcast', 'numpy.core.cdouble', 'numpy.core.complexfloating',
                        'numpy.core.concatenate', 'numpy.core.conjugate', 'numpy.core.csingle', 'numpy.core.divide',
                        'numpy.core.dot', 'numpy.core.double', 'numpy.core.empty', 'numpy.core.empty_like', 'numpy.core.equal',
                        'numpy.core.errstate', 'numpy.core.fastCopyAndTranspose', 'numpy.core.finfo', 'numpy.core.float32',
                        'numpy.core.float64', 'numpy.core.float_', 'numpy.core.geterrobj', 'numpy.core.greater',
                        'numpy.core.greater_equal', 'numpy.core.hstack', 'numpy.core.iinfo', 'numpy.core.inexact',
                        'numpy.core.inf', 'numpy.core.intc', 'numpy.core.integer', 'numpy.core.intp', 'numpy.core.invert',
                        'numpy.core.isfinite', 'numpy.core.isinf', 'numpy.core.isnan', 'numpy.core.isnat', 'numpy.core.isscalar',
                        'numpy.core.left_shift', 'numpy.core.less', 'numpy.core.less_equal', 'numpy.core.linspace', 'numpy.core.longdouble',
                        'numpy.core.maximum', 'numpy.core.multiply', 'numpy.core.ndarray', 'numpy.core.newaxis', 'numpy.core.not_equal',
                        'numpy.core.number', 'numpy.core.object_', 'numpy.core.ones', 'numpy.core.power', 'numpy.core.product', 'numpy.core.ravel',
                        'numpy.core.remainder', 'numpy.core.reshape', 'numpy.core.result_type', 'numpy.core.right_shift', 'numpy.core.rollaxis',
                        'numpy.core.shape', 'numpy.core.signbit', 'numpy.core.sin', 'numpy.core.single', 'numpy.core.size', 'numpy.core.sqrt',
                        'numpy.core.subtract', 'numpy.core.sum', 'numpy.core.swapaxes', 'numpy.core.take', 'numpy.core.transpose',
                        'numpy.core.ufunc', 'numpy.core.vstack', 'numpy.core.zeros', 'numpy.deprecate', 'numpy.dtype', 'numpy.expand_dims',
                        'numpy.eye', 'numpy.histogramdd', 'numpy.integer', 'numpy.intp', 'numpy.iscomplexobj', 'numpy.lib.add_newdoc',
                        'numpy.lib.asfarray', 'numpy.lib.i0', 'numpy.lib.imag', 'numpy.lib.iscomplexobj', 'numpy.lib.real', 'numpy.lib.triu',
                        'numpy.linalg.eigvals', 'numpy.linalg.inv', 'numpy.linalg.lstsq', 'numpy.ma.MAError', 'numpy.ma.MaskedArray',
                        'numpy.ma.filled', 'numpy.ma.getdata', 'numpy.ma.getmaskarray', 'numpy.ma.make_mask_descr', 'numpy.ma.masked',
                        'numpy.ma.masked_array', 'numpy.ma.nomask', 'numpy.ndarray', 'numpy.recarray', 'numpy_api', 'numpy_distutils',
                        'numpy_distutils.command.build_flib', 'numpy_distutils.command.cpuinfo', 'numpy_distutils.cpuinfo',
                        'numpy_distutils.fcompiler', 'org.python.modules.posix.PosixModule', 'pathlib', 'pkg_resources.extern.appdirs',
                        'pkg_resources.extern.packaging', 'pkg_resources.extern.six', 'pkg_resources.extern.six.moves', 'scipy',
                        'setuptools.extern.six', 'setuptools.extern.six.moves', 'setuptools_svn', 'sitecustomize', 'testing.Tester',
                        'urllib.error', 'urllib.parse', 'urllib.request', 'usercustomize', 'win32api', 'win32com.client.gencache',
                'win32con', 'win32pdh', 'win32pipe', 'wincertstore', 'winreg'
            ],

            'dll_excludes': [
                'KERNEL32.dll','GDI32.dll','WS2_32.dll','msvcrt.dll','COMCTL32.dll','COMDLG32.dll',
                'ole32.dll','SHELL32.dll','IMM32.dll','USER32.dll','OLEAUT32.dll','MSVCR90.dll',
                'MSVFW32.dll', 'AVIFIL32.dll', 'AVICAP32.dll', 'ADVAPI32.dll', 'CRYPT32.dll','WLDAP32.dll'
            ]
        }
    },

zipfile = None

)

希望有人可以帮我解决这个问题。

0 个答案:

没有答案