下面给出了为从IP Camera获取实时流而编写的代码.
from cv2 import *
from cv2 import cv
import urllib
import numpy as np
k=0
capture=cv.CaptureFromFile("http://IPADDRESS of the camera/axis-cgi/mjpg/video.cgi")
namedWindow("Display",1)
while True:
frame=cv.QueryFrame(capture)
if frame is None:
print 'Cam not found'
break
else:
cv.ShowImage("Display", frame)
if k==0x1b:
print 'Esc. Exiting'
break
Run Code Online (Sandbox Code Playgroud)
在运行代码时,我得到的输出是:
Cam not found
Run Code Online (Sandbox Code Playgroud)
我哪里错了?另外,为什么帧无?转换有问题吗?
I have an array and I would like to produce a smaller array by scanning a 2x2 non-overlappingly windows and getting the maximum. Here is an example:
import numpy as np
np.random.seed(123)
np.set_printoptions(linewidth=1000,precision=3)
arr = np.random.uniform(-1,1,(4,4))
res = np.zeros((2,2))
for i in xrange(res.shape[0]):
for j in xrange(res.shape[1]):
ii = i*2
jj = j*2
res[i][j] = max(arr[ii][jj],arr[ii+1][jj],arr[ii][jj+1],arr[ii+1][jj+1])
print arr
print res
Run Code Online (Sandbox Code Playgroud)
So a matrix like this:
[[ 0.393 -0.428 -0.546 0.103]
[ 0.439 -0.154 0.962 0.37 ]
[-0.038 -0.216 -0.314 0.458] …Run Code Online (Sandbox Code Playgroud) 我想测试ViBe算法的背景减法.目前我正在使用opencv库.我在opencv/samples/gpu/bgfg_segm.cpp和bgfg_vibe.cpp文件中找到了一个示例实现.这些文件在gpu模块下.现在我有一个没有GPU的系统.当我尝试运行代码时,它会在第一帧的初始化时崩溃.谁能告诉我如何解决这个问题?
提前致谢.
我正在实现一个简单的 grpc 服务发现。我想做的一件事是跟踪当前有多少客户端使用该服务,并且该服务将向服务注册中心报告。grpc server api 是否提供此类信息?我在这里遇到了一个有点类似的问题。https://github.com/grpc/grpc-java/issues/779。
在响应的第 1 点中,提到通过流 API 跟踪所有传入的 rpc。我该怎么做?
这是我想要实现的一个示例 rpc,RegisterInstance 将充当“pinger”,服务器将使用 etcd 的 ttl 来检查服务的活跃度。connected_client当注册中心注册了多个相同的服务类型时,注册中心将使用来确定将哪个服务 ip 发送回客户端。我的问题是如何connected_clients从服务端获取?
syntax = "proto3";
package registry_grpc;
service ServiceRegistry{
rpc GetInstance(ServiceRequest) returns(ServiceInstance) {}
rpc RegisterInstance(ServiceInstance) returns(ServiceInstance) {}
}
message ServiceRequest{
string service_type = 1;
}
message ServiceInstance{
int32 id = 1;
int32 connected_clients = 2;
string service_type = 3;
string host_address = 4;
int32 port = 5;
}
Run Code Online (Sandbox Code Playgroud)
我发现可以拦截每个传入的 rpc 调用。通过这种方式,我可以报告例如最后一秒的传入连接数。我想它可以作为工作负载的代理。
我正在尝试使用 np 的矢量化,但 imshow 显示黑色图像,如果我正确理解矢量化,它应该是白色的。我认为问题是输出类型,但我无法让它工作。
import numpy as np
import cv2
class Test():
def run(self):
arr = np.zeros((25,25))
arr[:]=255
cv2.imshow('white',arr)
flatarr = np.reshape(arr,25*25)
vfunc = np.vectorize(self.func)
#vfunc = np.vectorize(self.func,otypes=[np.int])#same effect
flatres = vfunc(flatarr)
shouldbewhite = np.reshape(flatres,(25,25))
cv2.imshow('shouldbewhite',shouldbewhite)
def func(self,a):
return 255
cv2.namedWindow('white',0)
cv2.namedWindow('shouldbewhite',0)
a = Test()
a.run()
cv2.waitKey(0)
Run Code Online (Sandbox Code Playgroud)