OpenCV是否可能使用相同的代码返回不同的结果? [英] Is it possible same code returns different result with openCV?
问题描述
我正在使用Raspberry-Pi
上的openCV
运行python
程序.
I'm running python
program with openCV
on Raspberry-Pi
.
我有个超级怪异的OpenCV Error
.看来它一定不会发生,但是确实发生了.
I got super wierd OpenCV Error
. It looks it must not be happend, but is happened.
简而言之,cv2.inRange()
裁切的mask
与相同的image
不同.
In short, mask
s croped by cv2.inRange()
is different with same image
.
- 将
images
处理为mask
并计算精度类型. - 如果未在(1.)中收集
mask
,这意味着image
的mask
都为黑色(空)np.array
,则跳过exception: Value Error
的迭代 命令.(因为代码araiseValue Error
中的min(empty np.array)
.) - 按时间间隔迭代(1.〜2.).
- process
images
intomask
and calculate kind of accuracy. - If
mask
is not gather in (1.), which meansmask
ofimage
is all black(empty)np.array
, it skip an iteration byexception: Value Error
command.(Becausemin(empty np.array)
in code araiseValue Error
.) - Iterate (1.~2.) with time interval.
问题:
我已经有两个星期以上的时间了.这是因为代码中的某些parameters
分配了错误的值.该paramters
大部分是根据mask
计算得出的,而mask
是根据image
裁切而成的.因此,我在迭代过程中保存了所有image
和mask
.发现有一个很小的mask
不能在9th iteration
Problem:
I've got same OpenCV Error
more than two weeks. It is because some parameters
in codes are assigned with wrong value. This paramters
are mostly calculated from mask
that is cropped from image
. So I saved all image
s and mask
s in the iterating procedure. And found that there were tiny mask
that must not be made at the 9th iteration
问题是,当我厌倦了在实验室桌面上以相同的9 th image
手动裁剪mask
时,它没有产生mask
,这意味着只制作了空的(黑色)mask
.但是在Raspberry-Pi
中的迭代运行过程中产生的mask
(白色区域)很小.
Problem is that when I tired to crop mask
with same 9 th image
manually on my labtop, it makes no mask
which means just empty(black) mask
is made. but there were very small mask
(white region) is made during iterative running in Raspberry-Pi
.
我检查了labtop和R-Pi
中的文件是否存在差异,但是两者相同.
这是images
:
首先是输入图像以创建Real
实例.第二是手动创建的mask
.尝试在R-Pi
中自动创建mask
.
I've checked if there are difference between files in labtop and R-Pi
, but both were same.
Here is the images
:
First is input image to make Real
instance. Second is manually created mask
. Thired is Automatically created mask
in R-Pi
.
pc和R-Pi
之间的唯一区别是:当我在pc中手动运行代码时,我使用了SDcard of R-Pi
中保存的image.jpg
.当在R-Pi
中迭代运行代码时,直接从R-pi camera module V2
Only difference between pc and R-Pi
is that: when I run code manually in pc, I have used saved image.jpg
from SDcard of R-Pi
. and when code is run in R-Pi
iteratively, image
is directly captured from R-pi camera module V2
我知道这很奇怪,许多人会认为代码中有错别字或某些错误.但是最近两个星期以来,我一直因为这个问题而受苦.我需要有关此类问题的任何线索.
I know it is verry wierd, and many people would think there are typo or something wrong in codes. But I have been suffered for this problem from last two weeks. I need any thread about this kind of problem.
是否有可能从openCV
或R-pi
中的相同代码收集了不同的结果?
Is there any possible cases that different result is gathered from same code in openCV
or R-pi
?
这是代码的一部分. Real
实例是循环迭代创建的.出现在OpenCV Error
上的行用#
标记.如果有人要求,我将上传更多.上传完整的代码有点长.
Here is some part of code. Real
instance is created iteratively in loop. The line occuring OpenCV Error
is marked with #
. If someone request, I will upload more. It is bit long to upload full code.
class Real:
__ob_low=np.array([25,100,50]) #27,65,100]) /25,100,50
__ob_high=np.array([33,255,255]) #[45,255,255]) /33,255,255
def __opening(self, mask):
kernel = np.ones((7, 1), np.uint8)
op = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
return op
def __init__(self, img_got,imgname):
img = img_got
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
mask_temp = cv2.inRange(hsv, self.__ob_low, self.__ob_high)
mask = self.__opening(mask_temp)
maskdir = "/home/pi/capstone/mask/" #
img_name = imgname #
cv2.imwrite(os.path.join(maskdir,img_name),mask) #
if not (np.any(mask)):
print("mask is empty")
array1 = np.transpose(np.nonzero(mask))
array2 = np.nonzero(mask)
ymin=min(array2[1])
ymax=max(array2[1])
xmin=min(array2[0])
xmax=max(array2[0])
self.x = xmax-xmin
self.y = ymax-ymin
self.ratio = self.x/self.y
self.img = img
self.mask = mask[(xmin):(xmax),(ymin):(ymax)]
推荐答案
在一个不同的系统上,我的代码出现了问题,事实证明,版本3.4.1和3.3.1与我的裁剪算法产生了不同的结果!
I had an issue with my code on a diffrent system and it turns out version 3.4.1 and 3.3.1 yields different result from my cropping algorithm!
这篇关于OpenCV是否可能使用相同的代码返回不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!