我首先使用此脚本从源代码安装openCV .当我测试它运行良好.
安装ROS动能后,打开python3并运行import cv2,出现以下错误:
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
Run Code Online (Sandbox Code Playgroud) 我在 Anaconda 环境下使用 Python 3.3。
我想模拟 sqlite3.connect。例如在MyTests(见下文)中,我想test_sqlite3_connect返回字符串connection而不是实际sqlite3.Connection对象。
我试过修补它,但这不起作用。
from unittest.mock import patch
import unittest
import sqlite3
@patch('sqlite3.connect')
def sqlite3_connect(self,connection_string):
print('connect with : {0}'.format(connection_string))
return 'connection '
class MyTests(unittest.TestCase):
def test_sqlite3_connect(self):
print('testing connection')
dbc = DataBaseClass()
class DataBaseClass():
def __init__(self):
print('initialising database class')
self.connection = sqlite3.connect('test database')
Run Code Online (Sandbox Code Playgroud) 我有以下代码,其中仅使用OpenCV显示图像:
import numpy as np
import cv2
class LoadImage:
def loadImage(self):
self.img=cv2.imread('photo.png')
cv2.imshow('Test',self.img)
self.pressedkey=cv2.waitKey(0)
# Wait for ESC key to exit
if self.pressedkey==27:
cv2.destroyAllWindows()
# Start of the main program here
if __name__=="__main__":
LI=LoadImage()
LI.loadImage()
Run Code Online (Sandbox Code Playgroud)
当窗口中显示照片后,我想在控制台(终端)上单击图片时显示鼠标的位置。我不知道如何执行此操作。有什么帮助吗?
由于以下错误,我正在尝试添加频道
ValueError:无法将输入数组从形状 (48,48) 广播到形状 (48,48,1)
代码:
img = cv2.imread(f,0)
resized = cv2.resize(img, (48,48), interpolation = cv2.INTER_AREA)
print(resized.shape)
(48, 48)
Run Code Online (Sandbox Code Playgroud)
但我需要像 (48,48,1) 这样的通道图像。
我该如何解决这个问题?
为了加快某些操作,我将图像传输到GPU内存.经过一些处理后,我必须裁剪一些区域:
image = cv2.UMat(image)
...
crop = image[y1:y2,x1:x2]
Run Code Online (Sandbox Code Playgroud)
问题是无法在GPU内存中切片图像.上面的代码会引发错误:"UMat对象不可订阅".我找到的解决方案是将图像传回到numpy对象,而不是将其切片,然后传回GPU:
image = cv2.UMat(image)
...
image = image.get()
crop = image[y1:y2,x1:x2]
crop = cv2.UMat(crop)
...
Run Code Online (Sandbox Code Playgroud)
但是上面的解决方案看起来很昂贵,因为向/从GPU内存传输数据需要时间.我觉得有一种方法可以在GPU内存中裁剪图像.任何提示?
opencv ×4
python ×2
python-2.7 ×2
python-3.x ×2
anaconda ×1
gpu ×1
keras ×1
mouse ×1
opencl ×1
ros ×1
tensorflow ×1
unit-testing ×1