当前位置: 首页>>代码示例>>Python>>正文


Python NeuralNetwork.classifyImage方法代码示例

本文整理汇总了Python中NeuralNetwork.NeuralNetwork.classifyImage方法的典型用法代码示例。如果您正苦于以下问题:Python NeuralNetwork.classifyImage方法的具体用法?Python NeuralNetwork.classifyImage怎么用?Python NeuralNetwork.classifyImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NeuralNetwork.NeuralNetwork的用法示例。


在下文中一共展示了NeuralNetwork.classifyImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from NeuralNetwork import NeuralNetwork [as 别名]
# 或者: from NeuralNetwork.NeuralNetwork import classifyImage [as 别名]
class Classifier:

    def __init__(self):
        self.alias = "[CLASSIFIER]>> "
        print self.alias , "Iniciando Clasificador..."
        self.netHandler = NeuralNetworksHandler()
        self.imageProcesor = ImagePreprocesor(wideSegment=150, highSegment=150, horizontalStride=50, verticalStride=50, withResizeImgOut=250, highResizeImgOut=250)
        networkModel, netMean, prototype, classes = self.netHandler.getNetworkByIndex(0)
        self.neuralNetwork = NeuralNetwork(networkModel,  prototype, netMean, classes)
        self.speaker = AudioPlayer()
        self.eventListener()


    def eventListener(self):
        tickTime = pygame.time.Clock()
        holdTime = 0
        pygame.init()
        DISPLAYSURF = pygame.display.set_mode((900, 900))
        DISPLAYSURF.fill((255, 255, 255, 255))
        while True:
            for event in pygame.event.get():
                if event.type == pygame.MOUSEBUTTONDOWN:
                    holdTime = tickTime.tick(60)
                    print self.alias, "DOWN: ", holdTime
                if event.type == pygame.MOUSEBUTTONUP:
                    if holdTime < 3000:
                        print "----------------------------"
                        print self.alias, "CLASSIFYING... "
                        print "----------------------------"
                        pygame.mixer.music.load("perro.wav")
                        self.takePicture()
                        #Para pruebas de reproducción --- (En mi compu no furula)
                        self.play("perro")
                        self.play("gato")
                        self.play("desconocido")
                        # -------------------------------
                        self.startClasification()
                        print self.alias, "UP: ", holdTime
                        holdTime = 0
                    else:
                        print self.alias, ": ", holdTime, " miliSegundos"
                        networkModel, netMean, prototype, classes = self.netHandler.getNextNet()
                        self.neuralNetwork = NeuralNetwork(networkModel, netMean, prototype, classes)
                        holdTime = 0
                if event.type == pygame.QUIT:
                    sys.exit(0)


    def takePicture(self):
        print self.alias , "Adquiriendo imagen"
        os.system("bash AdquisidorImagenes.sh")


    def startClasification(self):
        print self.alias, "Clasificando objetos en imágen"
        #numImages = self.imageProcesor.runSegmentation("img/photo.jpg")
        numImages = self.segment_entry_image("img/photo.jpg", 'img/segments/')
        for imageIndex in range(numImages):
            self.neuralNetwork.classifyImage('img/segments/cutout'+str(imageIndex)+'.jpg' , imageIndex)


    def segment_entry_image(self, url_image, url_output):
        img = open(url_image)

        width_image, height_image = img.size
        trajectory = get_circular_trajectory(width_image, height_image)
        segmenter = get_rectangular_segmenter(img, trajectory)

        i = 0
        image = segmenter.get_current_segment()
        image.pil_image.save(url_output+'cutout' + str(i) + '.jpg')

        i += 1
        while (segmenter.has_next_segment()):
            image = segmenter.get_next_segment()
            image.pil_image.save(url_output+'cutout' + str(i) + '.jpg')
            i += 1
        return i


    def play(self, audio):
        #pygame.init()
        print self.alias, "Reproduciendo sonido para clase ", audio
        pygame.mixer.music.load(self.audioPath + audio + self.audioFormat)
        pygame.mixer.music.play(0)
        clock = pygame.time.Clock()
        clock.tick(10)
        while pygame.mixer.music.get_busy():
            pygame.event.poll()
            clock.tick(10)
开发者ID:ESCOM-PROYS,项目名称:ClasificadorEnLinea,代码行数:92,代码来源:Classifier.py


注:本文中的NeuralNetwork.NeuralNetwork.classifyImage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。