- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是Python新手。
我编写了一些代码尝试将图片混合为新图片。
我完成了,但是浪费了太多时间。
所以我尝试使用 Numba 让代码在我的 GPU 上运行。但遇到一些警告和错误
os Ubuntu 16
pyhton version 3.5
for i in piclist:
img = cv2.imread(str(filepath)+'/'+str(i))
print (i)
b,g,r = cv2.split(img)
bcolorlist.append(b)
gcolorlist.append(g)
rcolorlist.append(r)
@jit(nopython = True)
def select(bcolorlist,gcolorlist,rcolorlist):
for i in range(len(bcolorlist)):
b = bcolorlist[i].reshape(2073600,1)
g = gcolorlist[i].reshape(2073600,1)
r = rcolorlist[i].reshape(2073600,1)
bcolorlist[i] = b
gcolorlist[i] = g
rcolorlist[i] = r
bbb = np.concatenate(bcolorlist, axis=1)
ggg = np.concatenate(gcolorlist, axis=1)
rrr = np.concatenate(rcolorlist, axis=1)
newb = []
newg = []
newr = []
for line in bbb:
newb.append(np.argmax(np.bincount(line)))
newb = np.array(newb)
for line in ggg:
newg.append(np.argmax(np.bincount(line)))
newg = np.array(newg)
for line in rrr:
newr.append(np.argmax(np.bincount(line)))
newr = np.array(newr)
return newb,newg,newr
没有@jit
也能正常工作
但使用@jit
将显示以下消息
test.py:61: NumbaWarning: Compilation is falling back to object mode WITH looplifting enabled because Function "select" failed type inference due to: Invalid use of Function() with argument(s) of type(s): (reflected list(array(uint8, 2d, C)), axis=Literalint)
根据建议立即更新代码
for f in files:
if is_img((os.path.splitext(f)[1])):
piclist.append(f)
start = time.time()
for i in piclist:
img = cv2.imread(str(filepath)+'/'+str(i))
b,g,r = cv2.split(img)
bcolorlist.append(b)
gcolorlist.append(g)
rcolorlist.append(r)
bcolorlist = array(bcolorlist)
gcolorlist = array(gcolorlist)
rcolorlist = array(rcolorlist)
@jit(nopython = True)
def select(bcolorlist,gcolorlist,rcolorlist):
r_res = np.zeros((len(bcolorlist), 2073600, 1), dtype=np.uint8)
g_res = np.zeros((len(gcolorlist), 2073600, 1), dtype=np.uint8)
b_res = np.zeros((len(rcolorlist), 2073600, 1), dtype=np.uint8)
for i in range(len(bcolorlist)):
r_res[i] = rcolorlist[i].reshape(2073600,1)
g_res[i] = gcolorlist[i].reshape(2073600,1)
b_res[i] = bcolorlist[i].reshape(2073600,1)
r_res = r_res.reshape(2073600, len(rcolorlist))
g_res = g_res.reshape(2073600, len(gcolorlist))
b_res = b_res.reshape(2073600, len(bcolorlist))
newr = np.zeros((2073600), dtype=np.uint8)
newg = np.zeros((2073600), dtype=np.uint8)
newb = np.zeros((2073600), dtype=np.uint8)
for i in range(b_res[:,0].size):
newr[i] = np.argmax(np.bincount(r_res[i,:]))
newg[i] = np.argmax(np.bincount(g_res[i,:]))
newb[i] = np.argmax(np.bincount(b_res[i,:]))
return newb, newg, newr
b, g, r = select(bcolorlist,gcolorlist,rcolorlist)
newb = b.reshape(1920,1080)
newg = g.reshape(1920,1080)
newr = r.reshape(1920,1080)
img = cv2.merge([newb, newg, newr])
end = time.time()
print (end - start)
工作正常!!!
但它没有使输出图像......
能麻烦您给点建议吗?
最佳答案
更新 - 使用 RGB 图像作为输入的工作示例。我过去没有用 Python 做过图像处理,所以这是一次很好的探索。下面的一些代码。请注意,我向该函数添加了一些输入参数,以使其更加通用。我还更改了一些变量名称,但这只是一个品味问题,所以不用担心。
import cv2
import numpy as np
from numba import njit
@njit
def select(b, g, r, n, w, h): # added number of input images, width and height
r_res = r.reshape(n, w*h) # flatten the images' rgb 2d arrays to 1d
g_res = g.reshape(n, w*h)
b_res = b.reshape(n, w*h)
newr = np.zeros((w*h), dtype=np.uint8)
newg = np.zeros((w*h), dtype=np.uint8)
newb = np.zeros((w*h), dtype=np.uint8)
for i in range(w*h): # this is what takes time...
newr[i] = np.argmax(np.bincount(r_res[:,i]))
newg[i] = np.argmax(np.bincount(g_res[:,i]))
newb[i] = np.argmax(np.bincount(b_res[:,i]))
newb = newb.reshape(w,h) # reshape back from 1d to 2d
newg = newg.reshape(w,h)
newr = newr.reshape(w,h)
return newb, newg, newr
imgs = ['D:/test/DSC02142.jpg', 'D:/test/DSC02606.jpg', 'D:/test/DSC01747.jpg']
bcolorlist, gcolorlist, rcolorlist = [], [], []
for i in imgs:
b, g, r = cv2.split(cv2.imread(i))
bcolorlist.append(b)
gcolorlist.append(g)
rcolorlist.append(r)
b = np.array(bcolorlist)
g = np.array(gcolorlist)
r = np.array(rcolorlist)
n, w, h = b.shape # assuming all images of equal width x height!
newb, newg, newr = select(b, g, r, n, w, h)
imgmerge = cv2.merge((newb, newg, newr))
cv2.imwrite('D:/test/output.jpg', imgmerge)
关于python - import Numba @jit meet warning message and @jit(nopython=True) 将显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57619756/
编程新手,但当我尝试创建此链接列表时,我收到错误消息“没有匹配的函数调用‘meetings::meetings()’”已经经历了几次,但我只是没有看到它是什么导致问题。 class meetings
为什么我运行此应用后在控制台中出现这些错误? 2019-11-17 19:49:21.997 INFO 10972 --- [nio-8080-exec-1] o.s.web.servlet.Dis
在 stackoverflow ( Appointment.Save and Appointment.Update always set IsMeeting to true ) 上已经讨论过,EWS
我已经实现了以下两种方法。 我已经完成了 jitsi 设置,其中我的 jitsi、jvb 和 jibri 在单独的服务器上运行。 我使用 docker 完成了 jitsi 设置,我在其中使用不同的容器
我正在使用 Jitsi-Meet iframe Api拥有自定义视频通话功能。它按预期工作。但是我想为此添加一个功能。该功能是在 http 负载时自动加入或自动开始 session 。我该怎么做而不是
我正在使用 Jitsi-Meet iframe Api拥有自定义视频通话功能。它按预期工作。但是我想为此添加一个功能。该功能是在 http 负载时自动加入或自动开始 session 。我该怎么做而不是
我有一个“people”表和一个“meetings”表,其中有两列:Person1_ID 和 Person2_ID。 当我为 person1_ID(该人是“人”之一)和 Person2_ID(也是“人
当我尝试通过 Zuul 网关访问服务 meeting 时,Zuul 无法将请求转发到相应的服务。以下是我面临的错误: nettflix.zuul.exception.ZuulException: Fo
我没有得到任何引用在我的 android 应用程序中添加 google meet 以通过提供其 sdk 的 zoom 等应用程序安排 session 最佳答案 没有适用于 Google Meet 的
我很好奇新的“打开/关闭”background blur functionality的 Google Meet(目前正在测试中)。我调查了一下,似乎正在使用 Tensorflow Lite 楷模: s
在 Google Meet ,如果您单击“立即演示”,然后单击“Chrome 选项卡”,它会打开一个窗口,让您可以从另一个选项卡共享。这与标准 Screen Capture API 不同。就好像你只是
在执行 jitsi-meet sdk 时遇到问题。 这些是正在发生的问题。 /Users/jeetk/Desktop/tring/iostring/ios/Pods/Target Support Fi
我有一台运行 Ubuntu 18.04 和 Nginx 的服务器,并在其上托管了一个功能齐全的 Jitsi Meet 实例。 另一方面,我有 2 个其他站点(一个是响应前端,另一个是后端),我需要它们
我正在使用 MediaDevices.getDisplayMedia()记录用户的屏幕。 理论上,我无法从 JS 缩小选择范围...... The specified constraints can'
我想添加仅允许经过身份验证的用户在 Jitsi Meet 中创建 session 的功能。我看到外部 API 的 jwt 参数、config.tokenAuthUrl 和 lib-jitsi-meet
我一直在查看 Jitsi Meet 平台。看起来很有希望在我的项目中使用。我无法在 Windows 服务器上安装 Jitsi Meet。没有可用于在 Windows 平台上安装的适当文档。 请分享在
我正在尝试为 this block 创建 jQuery 效果。这个想法是,当鼠标悬停在其他照片上时,其他照片会“看着”所选的照片。这是 html 代码。 ...
考虑这个函数,我正在使用 Django 和 torchadoweb def MeetingRecord(userid,mtngid,mesg): obj = Usage() obj.
如何获得“Google Classroom Meet Links”,有没有人找到从 API 或 vs. 中提取此信息的方法?我可以获得类(class)代码、教师电子邮件和链接,但无法访问类 sessi
我今天在我的 Chrome 中注意到了这一点。 Google Meet 在其“疑难解答”面板中显示了 CPU 使用率图表。我想知道是否有针对此的现有 API,或者这是一个我不知道的聪明技巧。 最佳答案
我是一名优秀的程序员,十分优秀!