我对 Python 很陌生,我想找到二进制图像的极端。黑色背景中间有一个白色形状,我想找到顶部、底部、左侧和右侧的封闭矩形。
我这样做的方法是在所有方向上找到第一个非零像素。
我的功能是这样的,但它只适用于 Y 轴。我怎样才能设法通过 X 轴?
def first_non_zero(img):
width = img.shape[1]
height = img.shape[0]
idx = 0
result = 0
for j in range(0, height):
idx = np.argmax(img[j])
if idx > 0:
result = j
break
return result
Run Code Online (Sandbox Code Playgroud) 我试图在 linux 上使用 subprocess.call() 调用 ffmpeg 命令,但我无法正确获取参数。之前,我使用了 os.system 并且它有效,但不推荐这种方法。
使用诸如“-i”之类的带破折号的参数会出现此错误
Unrecognized option 'i "rtsp://192.168.0.253:554/user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream"'.
Error splitting the argument list: Option not found
Run Code Online (Sandbox Code Playgroud)
使用像“i”这样没有破折号的参数会出现这个错误
[NULL @ 0x7680a8b0] Unable to find a suitable output format for 'i rtsp://192.168.0.253:554/user=admin&password=&channel=0&stream=0.sdp?real_stream'
i rtsp://192.168.0.253:554/user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream: Invalid argument
Run Code Online (Sandbox Code Playgroud)
这是代码
class IPCamera(Camera):
"""
IP Camera implementation
"""
def __init__(self,
path='\"rtsp://192.168.0.253:554/'
'user=XXX&password=XXX&channel=0&stream=0.sdp?real_stream\"'):
"""
Constructor
"""
self.path = path
def __ffmpeg(self, nb_frames=1, filename='capture%003.jpg'):
"""
"""
ffm_input = "-i " + self.path
ffm_rate = "-r 5"
ffm_nb_frames = "-vframes " + str(nb_frames) …Run Code Online (Sandbox Code Playgroud)