Каково различие между родителем и основой в Perl 5?

  1. Вместо того, чтобы выполнять размытие, набор номера, обнаружение неровных краев на моем уже пороговом изображении, я просто выполнил определение контура на своем исходном изображении.

  2. Затем я смог найти приличный контур для контура моего изображения, изменив команду findContour.

    _, контуры, _ = cv2.findContours (серый, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

  3. заменяя cv2.RETR_TREE на cv2.RETR_EXTERNAL I был в состоянии получить только контуры, которые были связаны с контуром объекта, вместо того, чтобы пытаться получить контуры внутри объекта. Переключение на cv2.CHAIN_APPROX_NONE не показало каких-либо заметных улучшений, но оно может обеспечить лучшие контуры для более сложной геометрии.

            for c in cnts:
            # compute the center of the contour
            M = cv2.moments(c)
            cX = int(M["m10"] / M["m00"])
            cY = int(M["m01"] / M["m00"])
    
            # draw the contour and center of the shape on the image
            cv2.drawContours(empty2, [c], -1, (255, 0, 0), thickness=1)
            perimeter = np.around(cv2.arcLength(c, True), decimals=3)
            area = np.around(cv2.contourArea(c), decimals=3)
    
            cv2.circle(empty2, (cX, cY), 7, (255, 255, 255), -1)
            cv2.putText(empty2, "center", (cX - 20, cY - 20),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    
            cv2.putText(empty2, "P:{}".format(perimeter), (cX - 50, cY - 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    
            cv2.putText(empty2, "A:{}".format(area), (cX - 100, cY - 100),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
    

    Используя приведенный выше код, я смог обозначить центроид каждого контура, а также информацию о периметре каждого контура и площади.

    enter image description here

    Однако я не смог выполнить тест, который бы выбрал, какой контур был моим желаемым контуром. У меня есть идея захватить мой объект в более идеальной обстановке и найти его центроид, периметр и связанную с ним область. Таким образом, когда я нахожу новый контур, я могу сравнить его с тем, насколько он близок к моим известным значениям.

    Я думаю, что этот метод может работать, чтобы удалить слишком большие или слишком маленькие контуры.

    Если кто-нибудь знает о лучшем решении, которое было бы фантастическим!

48
задан brian d foy 20 May 2009 в 09:39
поделиться

2 ответа

base tried to do one too many things – automatically handling loading modules but also allowing establishing inheritance from classes already loaded (possibly from a file whose name wasn't based on the module name). To sort of make it work, there was some hackery that caused surprising results in some cases. Rather than break backwards compatibility, a new, replacement pragma parent was introduced with cleaner semantics.

parent will be a core module as of 5.10.1.

Update: forgot that base handles fields (if you are using the fields pragma), which parent doesn't do.

51
ответ дан 26 November 2019 в 18:48
поделиться

Armed with the extra bit of information from ysth, I was able to see the differences in the docs:

The base pragma does the following things:

  • adds the named package to @ISA
  • loads the module with the same name as the named package using require (unless it detects that the package has already been loaded)
  • won't fail if a module with the same name as the package doesn't exist
  • dies if there are no symbols in the named package
  • if $VERSION does not exist in named package, base sets it to "-1, set by base.pm"
  • initializes the fields of the named package if they exist
  • does not call the import function of the named package

The parent pragma does the following things:

  • adds the named package to @ISA
  • loads the module with the same name as the named package using require
  • accepts an option that tells it not to die if a module with the same name as the package doesn't exist
37
ответ дан 26 November 2019 в 18:48
поделиться
Другие вопросы по тегам:

Похожие вопросы: