python-3.x - 无法使用 opencv 读取 .tdms 文件
问题描述
我需要使用 opencv 进行图像检测。输入文件来自传感器,正在尝试识别矩形。输入文件为 .tdms 格式。我无法为此使用opencv。
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/imgproc/src/color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'CvtHelper'
from nptdms import TdmsFile as td
import numpy as np
import cv2
from matplotlib import pyplot as plt
file = 'source.tdms'
with td.open(file) as tdms_file:
img = tdms_file.as_dataframe()
#use only intesting part of image
clip=img.iloc[700:1250,450:1550:]
img_rgb = np.array(clip,dtype=int)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('smallrectangle.jpeg', 0)
height, width = template.shape[::]
res = cv2.matchTemplate(img_gray, template, cv2.TM_SQDIFF)
plt.imshow(res, cmap='gray')
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = min_loc #Change to max_loc for all except for TM_SQDIFF
bottom_right = (top_left[0] + width, top_left[1] + height)
cv2.rectangle(img_rgb, top_left, bottom_right, (255, 0, 0), 2)
cv2.imshow("Matched image", img_rgb)
cv2.waitKey()
cv2.destroyAllWindows()
解决方案
推荐阅读
- go - 如何在响应式上下文取消的情况下入睡?
- json - 在 recyclerview 中显示对象数组中的某些项目
- scala - 在 Mockito 单元测试中抛出异常时,未调用 Future 的 .recover
- c# - VSTO Outlook 从约会中检索 TimeZoneStruct
- bash - 如何在bash中每3个代理选择一个用户名:密码?
- python-3.x - 不知道如何拆分 .dat 文件行
- c++ - 为什么我不能在 if 循环中使用动态变量?
- scala - Spark dataframe 列内容修改
- javascript - 插入符号用js改变背景颜色
- selenium - 无法使用 selenium 测试批处理作业结果需要 20-25 分钟才能完成