我有一个 numpy 数组字符串,它是通过使用转换的numpy.array2string
现在,我想要回我的 numpy 数组。
对我如何实现它有什么建议吗?
我的代码:
img = Image.open('test.png')
array = np.array(img)
print(array.shape)
array_string = np.array2string(array, precision=2, separator=',',suppress_small=True)
Run Code Online (Sandbox Code Playgroud)
PS 我的数组是3D数组而不是 1D 并且我使用,分隔符,而不是默认的空白
我需要使用 GStreamer 将数据传递到一些 OpenCV/Cuda 分类和深度学习系统。
问题是我对 GStreamer 和 Cuda 很陌生,所以我需要制作一些简单的示例,结合尽可能少的元素 - 这里是 OpenCV 和 Gstreamer。
cv.imshow()现在我只希望 GStreamer在循环中将“videotestsrc pattern=ball”传递到一帧一帧
问题是我似乎无法打开该cv.VideoCapture()元素 - 正确地因为管道错误
我已经花了几个小时了,现在已经“放弃”了
OpenCV 是 v3.4.0 - 使用 GStreamer 支持编译 Python 是 3.6.8
这是我现在的代码 -
我用谷歌搜索了一遍,并尝试了许多管道组合,但没有任何东西能让我打开视频捕获元素
#!/usr/bin/env python3
import cv2 as cv
cap = cv.VideoCapture("videotestsrc ! video/x-raw,framerate=20/1 ! appsink", cv.CAP_GSTREAMER)
# Commented out to continue to capture
# Evaluates true => app closes
#if not cap.isOpened():
# print('VideoCapture not opened')
# exit(0)
while(True):
ret, frame = cap.read()
print(ret) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 OpenCV 在 kivy 应用程序中创建视频上传器。但是,当我尝试上传视频时,出现以下错误
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0000021c356d9e00] moov atom not found
...
Run Code Online (Sandbox Code Playgroud)
在此期间屏幕变得无响应。我最近编辑了 save() 函数并添加了 uploadClass() 因为我收到了另一个错误。
主要.py
...
class SaveDialog(Screen):
save = ObjectProperty(None)
text_input = ObjectProperty(None)
cancel = ObjectProperty(None)
def save(self, path, filename):
for letter in os.path.join(path, filename):
print(letter)
def find(s, ch):
return [i for i, letter in enumerate(s) if letter == ch]
os_path_simpl = list(os.path.join(path, filename)) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用计算机视觉从 pdf/图像发票中提取数据。为此,我使用了基于 ocr 的 pytesseract。\n这是示例发票\n
\n您可以在下面找到相同的代码
import pytesseract\n\n\nimg = Image.open("invoice-sample.jpg")\n\ntext = pytesseract.image_to_string(img)\n\nprint(text)\nRun Code Online (Sandbox Code Playgroud)\n通过使用 pytesseract 我得到以下输出
\nhttp://mrsinvoice.com\n\n \n\n\xe2\x80\x99 Invoice\n\nYour Company LLC Address 123, State, My Country P 111-222-333, F 111-222-334\n\n\nBILLTO:\n\nfofin Oe Invoice # 00001\n\nAlpha Bravo Road 33 Invoice Date 32/12/2001\n\nP: 111-292-333, F: 111-222-334\n\nclient@example.net Nomecof Reps Bob\nContact Phone 101-102-103\n\nSHIPPING TO:\n\neine ce Payment Terms ash on Delivery\n\nOffice Road 38\nP: 111-333-222, F: 122-222-334 Amount Due: $4,170\noffice@example.net\n\nNO PRODUCTS / SERVICE QUANTITY / RATE / UNIT AMOUNT\nHOURS: PRICE\n\n1 tye 2 $20 $40\n\n2__| Steering …Run Code Online (Sandbox Code Playgroud) python ocr tesseract python-imaging-library document-layout-analysis
我正在使用PIL和OpenCV包加载图像。使用 加载图像时的高度和宽度与使用 加载图像时的高度和宽度相反。以下是打印使用这两个包加载的图像的高度和宽度的代码。PILcv2
file = \'conceptual_captions/VL-BERT/data/conceptual-captions/val_image/00002725.jpg\'\n# load image using PIL\nimport PIL.Image\npil = PIL.Image.open(file).convert(\'RGB\')\nw, h = pil.size\nprint("width: {}, height: {}".format(w, h))\nRun Code Online (Sandbox Code Playgroud)\n打印输出\nwidth: 1360, height: 765
# now using cv2\nimport cv2\nim = cv2.imread(file)\nprint("height, width, channels: {}".format(im.shape)) \nRun Code Online (Sandbox Code Playgroud)\n打印输出height, width, channels: (1360, 765, 3)
我下载了图像并使用 Mac 上的信息选项检查了图像的大小。信息有width = 765和height =\xe2\x80\x8a1360,与方法报告的相同cv2。为什么PIL给出错误的图像尺寸?
当图像非常少时就会出现此问题。我链接的图像就是这样的一张图像。对于其余图像,PIL和报告的高度和宽度cv2是相同的。
以下数据集类 -> dataloader 仅适用于 num_workers = 0,我不确定为什么。同一环境中的其他笔记本确实可以在 num_workers > 0 的情况下工作。这已经困扰我好几个月了!
不起作用的类:没有错误消息,只是在 next(iter(train_dl)) 上无限期地运行,而 num_workers = 0 则需要 1 秒。
class SegmentationDataSet(data.Dataset):
def __init__(self, fnames, rle_df=None, path=train_val_dir):
self.fnames = fnames
self.rle_df = rle_df
self.path = path
def __len__(self):
return len(self.fnames)
def __getitem__(self, index:int):
img_id = self.fnames[index]
mask = None
im = torchvision.io.read_image(self.path + img_id).float()
if self.rle_df is not None:
rle = self.rle_df.loc[self.rle_df['id']==img_id]['rle']
if not pd.isnull(rle).values[0]:
rle = rle.values[0]
mask = rle2mask(rle, [1024,1024])
mask = torch.from_numpy(np.expand_dims(mask,0))
else:
mask = torch.zeros([1,1024,1024])
return …Run Code Online (Sandbox Code Playgroud) 我正在使用Camera2 扩展示例进行实时图像处理。在此之前我使用的是Camera2 Basic。在基本示例中,我从下面的代码片段中获取实时图像。
val captureRequest = camera.createCaptureRequest(
CameraDevice.TEMPLATE_PREVIEW
).apply {
addTarget(getViewDataBinding()?.viewFinder!!.holder.surface)
addTarget(imageReader.surface)
}
// This will keep sending the capture request as frequently as possible until the
// session is torn down or session.stopRepeating() is called
captureRequest.set(
CaptureRequest.CONTROL_MODE,
CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE
)
captureRequest.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF)
session.setRepeatingRequest(captureRequest.build(), null, cameraHandler)
Run Code Online (Sandbox Code Playgroud)
你可以看到,我在上面的代码中添加了目标imageReader。我使用扩展 API 几乎类似的方式。但是在ExtensionSessionConfiguration配置方法中。
cameraExtensionSession = session
try {
val captureRequest = camera.createCaptureRequest(
CameraDevice.TEMPLATE_PREVIEW
).apply {
addTarget(previewSurface)
addTarget(imageReader.surface)
}
captureRequest.set(
CaptureRequest.CONTROL_MODE,
CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE
)
cameraExtensionSession.setRepeatingRequest(
captureRequest.build(),
Dispatchers.IO.asExecutor(), captureCallbacks
) …Run Code Online (Sandbox Code Playgroud) java android image-processing android-camera android-camera2
我是 Opencv 的新手,尝试在 mac 上运行轨迹栏,但它给了我一个分段错误。代码是:
import numpy as np
import cv2 as cv
def nothing(x):
pass
img = np.zeros((300,512,3), np.uint8)
cv.namedWindow('image')
cv.createTrackbar('R', 'image', 0, 255, nothing)
cv.createTrackbar('G', 'image', 0, 255, nothing)
cv.createTrackbar('B', 'image', 0, 255, nothing)
switch = '0 : OFF \n1 : ON'
cv.createTrackbar(switch, 'image', 0, 1, nothing)
while True:
cv.imshow('image', img)
k = cv.waitKey(1)
if k == 27:
break
r = cv.getTrackbarPos('R', 'image')
g = cv.getTrackbarPos('G', 'image')
b = cv.getTrackbarPos('B', 'image')
s = cv.getTrackbarPos(switch, 'image')
if s == …Run Code Online (Sandbox Code Playgroud) 我有一个从网上下载的图像(验证码)。

当我加载时,opencv它似乎失去了它的属性,或者只是将透明背景与深色/黑色混合:

目前,代码除了再次加载文字外什么也没做:
captchaImg = cv2.imread('captcha1.png')
cv2.imwrite("captcha2.png", captchaImg)
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用选项 0、1、2、3 加载,但结果是相同的。
由于某种我无法理解的原因, open cv 函数cv2.moments返回一个字典,其中我提供的轮廓的值全部为零。这是一个 MWE:
contour = [[[271, 67]],
[[274, 67]],
[[275, 68]],
[[278, 68]],
[[279, 69]],
[[283, 69]],
[[284, 70]],
[[287, 70]],
[[288, 71]],
[[291, 71]],
[[292, 72]],
[[295, 72]],
[[292, 72]],
[[291, 71]],
[[288, 71]],
[[287, 70]],
[[284, 70]],
[[283, 69]],
[[279, 69]],
[[278, 68]],
[[275, 68]],
[[274, 67]]]
contour = np.asarray(contour)
moments = cv2.moments(contour)
Run Code Online (Sandbox Code Playgroud)
结果:
print(moments)
{'m00': 0.0, 'm10': 0.0, 'm01': 0.0, 'm20': 0.0, 'm11': 0.0, 'm02': 0.0, 'm30': 0.0, 'm21': 0.0, 'm12': 0.0, 'm03': …Run Code Online (Sandbox Code Playgroud)