imcow在opencv-python中不起作用

时间:2014-12-25 13:37:01

标签: python opencv ubuntu

发生错误,程序在执行cv2.imshow时崩溃。

我的代码只是

import cv2
sscv = cv2.imread('/home/myuser/Pictures/Workspace 1_007.png',0)
cv2.imshow("screenshot image", sscv)
cv2.waitKey(0)

显示的错误是

    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: cannot register existing type 'GdkDisplayManager'
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: g_once_init_leave: assertion 'result != 0' failed
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: g_object_new: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: invalid (NULL) pointer instance
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: cannot register existing type 'GdkDisplay'
      cv2.imshow("screenshot image", sscv)
    /home/mallory/workspace/python-autoaction/test/test_xutils.py:11: Warning: g_type_register_static: assertion 'parent_type > 0' failed
      cv2.imshow("screenshot image", sscv)
    Segmentation fault (core dumped)

使用

  • Ubuntu 14.0.4
  • Python 2.7.6
  • cv2 2.4.8

那有什么问题?

1 个答案:

答案 0 :(得分:1)

再次尝试安装这些依赖项,如果问题仍然存在,请告诉我

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
make -j2
sudo checkinstall
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

之后就去做

myApp.factory('ageService', function ($http, $q) {

    var deferred = $q.defer();

    var ageGroupData = {};

    //setter for Age group
    var addAgeGroupData = function (data) {
        ageGroupData = data;
    }

    //getter for Age group
    var getAgeGroupData = function () {
        return ageGroupData;
    }


    var fetch = function (ageGroudId) {
        $http({
            url: 'http://localhost:1337/agegroup/find/',
            method: "POST",
            data: JSON.stringify({
                "id": ageGroudId
            }),
            headers: {
                'Content-Type': 'application/json'
            }
        }).success(function (data, status, headers, config) {
            if (data.success) {

                addAgeGroupData(data);
                deferred.resolve(ageGroupData);
            } else {
                //do nothing
                console.log(data);
                deferred.reject("error");
            }
        }).error(function (data, status, headers, config) {
            console.log(data);
        });
        return deferred.promise;
    };

    return {
        getAgeGroupData: getAgeGroupData,
        addAgeGroupData: addAgeGroupData,
        fetch: fetch
    };

});