我的代码是:
import gluoncv as gcv
net = gcv.model_zoo.get_model('ssd_512_mobilenet1.0_voc', pretrained=True)
windowName = "ssdObject"
cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 1280, 720)
cv2.moveWindow(windowName, 0, 0)
cv2.setWindowTitle(windowName, "SSD Object Detection")
while True:
# Check to see if the user closed the window
if cv2.getWindowProperty(windowName, 0) < 0:
# This will fail if the user closed the window; Nasties get printed to the console
break
ret_val, frame = video_capture.read()
frame = mx.nd.array(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)).astype('uint8')
rgb_nd, frame = gcv.data.transforms.presets.ssd.transform_test(frame, short=512, max_size=700)
# # Run frame through network
class_IDs, scores, …
Run Code Online (Sandbox Code Playgroud) 我有大约30个SEM(扫描电子显微镜)图像:
你看到的是玻璃基板上的光刻胶柱.我想做的是获得x和y方向的平均直径以及x和y方向的平均周期.
现在,我不想手动进行所有测量,我想知道,如果有可能使用python和opencv自动化它?
编辑:我尝试了下面的代码,它似乎正在检测圆圈,但我真正需要的是椭圆,因为我需要x和y方向的直径.
......我还没看到如何获得规模呢?
import numpy as np
import cv2
from matplotlib import pyplot as plt
img = cv2.imread("01.jpg",0)
output = img.copy()
edged = cv2.Canny(img, 10, 300)
edged = cv2.dilate(edged, None, iterations=1)
edged = cv2.erode(edged, None, iterations=1)
# detect circles in the image
circles = cv2.HoughCircles(edged, cv2.HOUGH_GRADIENT, 1.2, 100)
# ensure at least some circles were found
if circles is not None:
# convert the (x, y) coordinates and radius of the circles …
Run Code Online (Sandbox Code Playgroud) cv2.imshow正在发生一些奇怪的事情.我正在编写一段代码并想知道为什么我的一个操作不起作用(通过观察cv2.imshow来诊断).在恼怒的情况下,我最终将相同的图像写入文件,其中看起来很好.为什么cv2.imshow显示二进制图像(下面的第一个图像),而cv2.imwrite按预期写入灰度图像(第二个图像)?我以前从未遇到过显示灰度图像的问题!
cv2.imshow('Latest', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
distTransform = cv2.distanceTransform(src=image,distanceType=cv2.DIST_L2,maskSize=5)
cv2.imwrite('distanceTransform.png', distTransform)
cv2.imshow('Latest', distTransform)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
我正在尝试将OpenCV与Python结合使用,以便检测来自Raspberry Pi摄像机的实时视频源中的正方形。但是,下面的代码中的cv2.GaussianBlur
和cv2.Canny
函数导致以下错误:“ TypeError:numpy.ndarray'对象不可调用”。
我似乎无法解决该错误。任何帮助表示赞赏。
import cv2
# load the video
camera = cv2.VideoCapture(0)
# keep looping
while True:
# grab the current frame and initialize the status text
(grabbed, frame) = camera.read()
status = "No Targets"
# check to see if we have reached the end of the
# video
if not grabbed:
break
# convert the frame to grayscale, blur it, and detect edges
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blurred = …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Opencv 和 python 来检测形状然后裁剪它们。我已经成功地做到了这一点,但是现在我正在尝试拍摄裁剪后的图像并删除它们的背景。
图像内部有一个圆圈,周围环绕着灰色。(它可以是灰色的,也可以是不止一种颜色)。
如何删除圆形边框(黑色)周围的颜色 - 我们可以将灰色转换为黑色 - 作为边框颜色,甚至完全删除它并使其透明。
结果图像应仅包含圆圈。
使用python-OpenCV,我已成功读取以下图像,检测矩形,裁剪它们并将每个矩形保存为图像。
这是我成功裁剪并另存为图像的矩形的示例。(因此将有12个)
然后处理每个矩形图像,以隔离圆并为每个圆创建一个新图像-使用cv2.HoughCircles我也成功做到了。
图像的输出A
包含圆圈,如下所示:
现在:我需要做的是删除绿色圆圈以外的所有内容,并将绿色圆圈以外的所有内容转换为黑色,然后得到B
(仅绿色圆圈):
现在的问题是:如何获得B
从A
。
我从OpenCV中获取代码:删除图像的背景,但不适用于该图像A
,而是输出此类图像:
circle_path_test = 'D:\rec.png'
img = cv2.imread(circle_path_test)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
## (2) Threshold
th, threshed = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV|cv2.THRESH_OTSU)
## (3) Find the min-area contour
_, cnts, _ = cv2.findContours(threshed, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = sorted(cnts, key=cv2.contourArea)
for cnt in cnts:
if cv2.contourArea(cnt) > 100:
break
## (4) Create mask and do bitwise-op
mask …
Run Code Online (Sandbox Code Playgroud) 我想将单应性应用于以下几点:
array([[-7.4894, 1.8873],
[-7.4973, 1.8543],
[-7.5375, 1.6725],
[-7.5681, 1.522 ],
[-7.5961, 1.371 ],
[-7.6252, 1.2013],
[-7.6504, 1.031 ],
[-7.667 , 0.8985],
[-7.6817, 0.7657],
[-7.6954, 0.613 ],
[-7.7054, 0.4786],
[-7.7124, 0.3452],
[-7.7182, 0.1931],
[-7.7215, 0.0866],
[-7.7716, 0.0872],
[-7.7715, 0.0929],
[-7.7651, 0.2884],
[-7.7587, 0.4269],
[-7.7528, 0.5233],
[-7.7418, 0.6616],
[-7.7275, 0.8116],
[-7.7048, 1.0032],
[-7.6916, 1.0988],
[-7.6686, 1.2478],
[-7.6352, 1.4379],
[-7.6091, 1.5741],
[-7.5784, 1.7219],
[-7.538 , 1.8995],
[-7.4894, 1.8873]], dtype=float32)
Run Code Online (Sandbox Code Playgroud)
我的相机单应矩阵是这样的:
array([[ 3.9643041e-04, 6.5913662e-07, 3.1965813e-03],
[ 7.4297395e-07, -3.9652368e-04, -4.4492882e-04],
[-9.3076696e-06, -3.5773560e-06, 1.0000000e+00]], dtype=float32)
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 …
我有以下 ORB 关键帧匹配代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
img1 = cv2.imread("C:\\Users\\user\\Desktop\\picture\\Pikachu_Libre.png",0)
img2 = cv2.imread("C:\\Users\\user\\Desktop\\picture\\Pikachu_Libre.png",0)
# Initiate STAR detector
orb = cv2.ORB_create()
# find the keypoints with ORB
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1,des2)
# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)
# Draw first 10 matches.
img3 = cv2.drawMatches(img1,kp1,img2,kp2,None,matches[:10], flags=2)
plt.imshow(img3),plt.show()
Run Code Online (Sandbox Code Playgroud)
我运行后出现以下错误:
img3 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个我检测到红色的程序.但是有时它比平时更暗,所以我不能只使用一个值.什么是检测不同色调红色的好范围?我目前使用的范围是128,0,0 - 255,60,60,但有时它甚至都没有检测到我放在它前面的红色物体.
我收到此错误Error when checking input: expected conv2d_11_input to have 4 dimensions, but got array with shape (300, 300, 3)
如何将 RGB 图像传递给 CNN?如何枚举样本以创建 4D 图像?
我想手动将 RGB 图像转换为灰度图像。我想知道的是如何获得 RGB 像素的红/蓝/绿值?
img = cv2.imread("images/penguins.jpg",0)
grey = img
for i in range(0,grey.shape[0]-1):
for j in range(0,grey.shape[1]-1):
img[i,j]=[ ]
Run Code Online (Sandbox Code Playgroud)
我不知道接下来要做什么
谢谢,对不起我的英语不好
opencv ×11
python ×11
numpy ×5
image ×4
arrays ×1
colors ×1
homography ×1
mxnet ×1
orb ×1
python-3.x ×1