我一直在尝试从Pycharm和终端安装OpenCV和cv2,如下所示:
pip install --user opencv
pip install --user cv2
Run Code Online (Sandbox Code Playgroud)
但是我收到了以下错误:
Collecting opencv
Could not find a version that satisfies the requirement opencv (from versions: )
No matching distribution found for opencv
Run Code Online (Sandbox Code Playgroud)
和
Collecting cv2
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
Run Code Online (Sandbox Code Playgroud)
如何修复这些并正确安装软件包?我正在使用python 3.4.
我有一个由 True 和 False 值组成的矩阵。我想将此打印为图像,其中所有 True 值都是白色,而 False 值是黑色。该矩阵称为索引。我尝试了以下方法:
indices = indices.astype(int) #To convert the true to 1 and false to 0
indices*=255 #To change all the 1's to 255
cv2.imshow('Indices',indices)
cv2.waitKey()
Run Code Online (Sandbox Code Playgroud)
这是打印全黑图像。当我尝试 print 时(indices==255).sum()
,它返回 669 的值,这意味着索引矩阵中有 669 个元素/像素应该是白色的。但我只能看到纯黑色的图像。我怎样才能解决这个问题?
我已经加载了预先训练好的VGG面部CNN并成功运行了它.我想从第3层和第8层中提取超列平均值.我正在关注从此处提取超列的部分.但是,由于get_output函数不起作用,我不得不做一些更改:
进口:
import matplotlib.pyplot as plt
import theano
from scipy import misc
import scipy as sp
from PIL import Image
import PIL.ImageOps
from keras.models import Sequential
from keras.layers.core import Flatten, Dense, Dropout
from keras.layers.convolutional import Convolution2D, MaxPooling2D, ZeroPadding2D
from keras.optimizers import SGD
import numpy as np
from keras import backend as K
Run Code Online (Sandbox Code Playgroud)
主功能:
#after necessary processing of input to get im
layers_extract = [3, 8]
hc = extract_hypercolumn(model, layers_extract, im)
ave = np.average(hc.transpose(1, 2, 0), axis=2)
print(ave.shape)
plt.imshow(ave) …
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现这个版本的定向梯度直方图(HOG)。我的代码如下。我的代码中唯一的区别是我曾经opencv
读取图像并将其转换为灰度。
import cv2
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, color, exposure
filename = 'match1/hockey15.jpg'
im = cv2.imread(filename)
gr = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
print im.shape
image = gr
fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),
cells_per_block=(1, 1), visualise=True)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)
ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Input image')
ax1.set_adjustable('box-forced')
# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 0.02))
ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients') …
Run Code Online (Sandbox Code Playgroud) python image-processing scikit-image histogram-of-oriented-gradients
我一直在努力为python 2.7而不是3.4安装numpy,这两者都在我的ubuntu上。我试过了:
须藤 pip2 安装 numpy
但它说
Requirement already satisfied (use --upgrade to upgrade): numpy in /usr/lib/python2.7/dist-packages
Run Code Online (Sandbox Code Playgroud)
但是当我进入 python shell 并输入时import numpy
,它会抛出一个ImportError
python --version prints `Python 2.7.5`
Run Code Online (Sandbox Code Playgroud)
即使查看了其他 SO 问题的各种答案,我也不知道问题是什么。是否安装了 numpy 并且由于某种原因我无法使用它或者没有安装它?请帮忙。
我试图在一组曲棍球图像中隔离某些彩色线条(场线).我已应用了Hue亮度饱和度(HLS)色彩空间滤镜,并设法传递原始图像中指定HLS范围内的所有组件.然而,图像的某些部分也正在通过,因为它们满足颜色范围,例如,人群的一部分和比赛场地的部分.但是,我想只隔离所需的行.我怎样才能做到这一点?
注意:我有蓝色和黄色的单独程序,因为它们需要不同的HLS范围.在某些图像中,有多行.另外,从我放置的第二张图片中可以看出,线条可能略微弯曲.在第二张图片中,如果我只能获得直线部分就足够了.
我尝试了各种图像转换和形态操作,没有运气.我已经对HLS范围进行了很多实验,并设置它们以便在我拥有的一组图像上产生最佳效果,但我仍然没有得到满意的结果.
原始图片:
码:
import cv2
import numpy as np
frame = cv2.imread('hockey4.jpg')
width=900
height=600
frame = cv2.resize(frame,(width,height))
# Convert BGR to HLS
hls = cv2.cvtColor(frame, cv2.COLOR_BGR2HLS)
#HLS ranges for blue
#lower array defines the lower limit and upper array defines the upper limit of the range
#The mask is a binary image where the output is white if the corresponding pixel in the input image is between the range specified by upper and lower limits
#blue
lower = …
Run Code Online (Sandbox Code Playgroud) 如何在 lua 中声明一个列表,如以下 python 代码,以及如何索引该列表?
在python中列出:
image_list=[];
Run Code Online (Sandbox Code Playgroud) 我编写了一个程序,在一些计算后打印一个矩阵,我得到了nan
所有元素的输出.我想for
在矩阵的第一个元素变为nan
理解问题时立即打破循环.我怎样才能做到这一点?在终端中,我打印了a
包含nan
所有元素并输入的矩阵a[1][1]=="nan"
,a[{{1},{1}}]=="nan"
两者都返回false
.他们为什么不回来false
,我应该使用什么声明呢?
在下面的循环中,最初lines_hp[0]
不是NoneType
. 但经过一些操作后,它会变成NoneType
,我想在发生这种情况时打破循环。经过一些循环迭代后,lines_hp[0]
更改为NoneType
,但是当我想使用 来识别它时lines_hp[0] is not None
,我收到错误:'NoneType' object has no attribute '__getitem__'
。我怎样才能解决这个问题?
while lines_hp[0] is not None:
print lines_hp[0] is not None
#some operation to change lines_hp[0]
Run Code Online (Sandbox Code Playgroud)
我已经了解了许多有关如何检测 NoneType 项目的问题和答案,但我仍然收到上述错误。
python ×7
opencv ×3
lua ×2
histogram-of-oriented-gradients ×1
image ×1
keras ×1
nan ×1
nonetype ×1
numpy ×1
pycharm ×1
python-2.7 ×1
scikit-image ×1
theano ×1
vgg-net ×1