OpenCV是否可能使用相同的代码返回不同的结果? [英] Is it possible same code returns different result with openCV?

查看:93
本文介绍了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, masks croped by cv2.inRange() is different with same image.

  1. images处理为mask并计算精度类型.
  2. 如果未在(1.)中收集mask,这意味着imagemask都为黑色(空)np.array,则跳过exception: Value Error的迭代 命令.(因为代码araise Value Error中的min(empty np.array).)
  3. 按时间间隔迭代(1.〜2.).
  1. process images into mask and calculate kind of accuracy.
  2. If mask is not gather in (1.), which means mask of image is all black(empty) np.array, it skip an iteration by exception: Value Error command.(Because min(empty np.array) in code araise Value Error.)
  3. Iterate (1.~2.) with time interval.

问题:

我已经有两个星期以上的时间了.这是因为代码中的某些parameters分配了错误的值.该paramters大部分是根据mask计算得出的,而mask是根据image裁切而成的.因此,我在迭代过程中保存了所有imagemask.发现有一个很小的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 images and masks 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.

是否有可能从openCVR-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆