Exemplo n.º 1
0
 def plot_txts_from_path(self, path):
     if self.is_given_path_a_dir(path):
         txt_files = self.getTxtFilesFromDirectory(path)
         for txtFile in txt_files:
             file_name = util.getLastTokenOfPath(txtFile)[0]
             os.mkdir(file_name)
             self.plot_txt_file(path + "/" + txtFile, file_name + "/" + file_name)
     else:
         file_name = util.getLastTokenOfPath(path)[0]
         os.mkdir(file_name)
         self.plot_txt_file(path, file_name + "/" + file_name)
Exemplo n.º 2
0
    def process(self, videoPath):
        fileName = util.getLastTokenOfPath(videoPath)[0]
        videoCutter = VideoCutter()
        frames = videoCutter.cutVideo(videoPath, self.framesNro, self.rotate,
                                      self.typeOfCut)

        x = 1
        edgeImages = []
        for frame in frames:
            print("Processing frame number " + str(x) + "...")
            try:
                treatedImage = self.detector.detectPersonFromNumpy(frame)
                edgeImages.append(
                    self.edgeDetector.getImageBluryEdgesFromNumpy(
                        treatedImage))
                print("Done.\n")
            except:
                print("Human not found on frame number " + str(x))
            x = x + 1
        if (len(edgeImages) > 0):
            print("Concatenating all images")
            directory = util.getPathOfVideoDirectory(videoPath)
            data = util.combineImages(edgeImages)
            util.saveImage(data, fileName + "Edges", ".jpg")
            util.saveImageToPath(data, fileName + "Edges", ".jpg", directory)
            print("Done.")
        else:
            print("Unsuccesful process, theres no human on the video clip " +
                  videoPath + "\n")
Exemplo n.º 3
0
 def process_from_path(path):
     image = cv2.imread(path)
     gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
     classfier_path = "C:/Users/Jp/Desktop/brazo/data/cascade.xml"  #"brazo_cascade.xml"
     detector = cv2.CascadeClassifier(classfier_path)
     rects = detector.detectMultiScale(gray,
                                       scaleFactor=1.1,
                                       minNeighbors=5,
                                       minSize=(500, 500))
     print(rects)
     for (i, (x, y, w, h)) in enumerate(rects):
         cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
         cv2.putText(image, "arm #{}".format(i + 1), (x, y - 10),
                     cv2.FONT_HERSHEY_SIMPLEX, 0.55, (0, 0, 255), 2)
     file_name = util.getLastTokenOfPath(path)[0]
     util.saveImageToPath(image, file_name + "cascade", ".jpg",
                          util.getPathOfVideoDirectory(path))
Exemplo n.º 4
0
    def process(self, video_path):
        frames = self.cutVideo(video_path)
        record = self.get_alike_weights(frames)
        self.directory = util.getPathOfVideoDirectory(video_path)
        self.videoName = util.getLastTokenOfPath(video_path)[0]

        maxima_indexes, maxima_values, global_indexes = self.process_for_getting_max_alike(record)

        print(maxima_indexes)
        print(maxima_values)
        print(global_indexes)

        global_indexes = self.post_process_filter(frames, global_indexes)

        if self.combineImages:
            self.combine_frames(frames, global_indexes)
        else:
            self.save_critical_frames(frames, global_indexes)
Exemplo n.º 5
0
    def cutVideo(self, videoPath, outFramesNumber, rotate, typeOfCut):
        cap = cv2.VideoCapture(videoPath)
        videoName = util.getLastTokenOfPath(videoPath)
        print("Video " + videoName[0] + " loaded")
        #numero total de frames
        frameCount = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

        constantForProbablity = 5
        cutOn = 0
        cont = 0
        listOfFrames = []

        while (cap.isOpened()):
            ret, frame = cap.read()
            cont += 1

            if cont >= cutOn:
                #Rotar imagen
                if rotate:
                    rotatedFrame = ndimage.rotate(frame, 270)
                    listOfFrames.append(rotatedFrame)
                else:
                    listOfFrames.append(frame)
                # Corte en el frame:
                if typeOfCut == "Constant":
                    cutOn = frameCount / outFramesNumber + cont
                if typeOfCut == "Probabilistic":
                    cutOn = frameCount / outFramesNumber + cont
                    cutOn = self.getRandomCut(cutOn, constantForProbablity)
                if len(listOfFrames) == outFramesNumber:
                    break
            else:
                if cutOn >= frameCount:
                    break

        cap.release()
        return listOfFrames
Exemplo n.º 6
0
 def isGivenPathADir(self, path):
     finalToken = util.getLastTokenOfPath(path)
     return len(finalToken) == 1
Exemplo n.º 7
0
 def isGivenFileMP4File(self, file):
     finalToken = util.getLastTokenOfPath(file)
     return finalToken[1] == self.MP4_EXTENSION
Exemplo n.º 8
0
 def is_given_path_a_dir(self):
     final_token = util.getLastTokenOfPath(self.path)
     return len(final_token) == 1
Exemplo n.º 9
0
 def is_given_file_jpg_file(self, file):
     final_token = util.getLastTokenOfPath(file)
     return final_token[1] == self.JPG_EXTENSION
Exemplo n.º 10
0
 def combine_name(path, to_combine):
     file_name, extension = util.getLastTokenOfPath(path)[:2]
     new_file_name = file_name + to_combine + "." + extension
     path = util.getPathOfVideoDirectory(path)
     return path + new_file_name
Exemplo n.º 11
0
 def is_file_extension(file, extension):
     final_token = util.getLastTokenOfPath(file)
     return final_token[1] == extension