Exemple #1
0
    def start(self):
        try:
            self.logger.info("Starting Application..")

            if self.auto_reload:
                self.load_reconstruction_from_pickle()

            else:
                self.reconstruction = Reconstruction(
                    slide_score_api=self.slide_score_api,
                    slide_score_user=self.slide_score_user,
                    parent=self,
                    logger=self.logger)
                self.reconstruction.set_slide_score_study_and_case_id(
                    slide_score_study_id=self.slide_score_study_id,
                    slide_score_case_id=self.slide_score_case_id)
                self.reconstruction.set_macro_photo(
                    macro_photo_path=self.macro_photo_path)
                self.reconstruction.load_coupes(
                    max_cnt_coupes=self.max_cnt_coupes)
        except:
            self.logger.error(
                f'Unexpected error: {sys.exc_info()[0]} \n {traceback.format_exc()}'
            )
            pass
Exemple #2
0
 def reconstruct(self, K, imageSize, markers):
     
     def normalizeMarkersCostFunction(parameters):
         x = parameters[0]
         y = parameters[1]
         
         r2 = x*x + y*y
         r4 = r2*r2
         r6 = r4*r2
         r_coeff = 1 + k1*r2 + k2*r4 + k3*r6
         xx = K[0, 0]*x*r_coeff + K[0, 2]
         yy = K[1, 1]*y*r_coeff + K[1, 2]
         
         return xx - m.x, yy - m.y
     
     k1, k2, k3 = 0, 0, 0 # polynomial radial distortion
     #Normalize markers
     normalizedMarkers = []
     for m in markers:
         initParams = numpy.zeros(2)
         initParams[0] = (m.x - K[0, 2]) / K[0, 0]
         initParams[1] = (m.y - K[1, 2]) / K[1, 1]
         result = optimize.root(normalizeMarkersCostFunction, initParams, method='lm')
         #print(initParams[0], initParams[1], m.x, m.y, result.x[0], result.x[1])
         normalizedMarkers.append(Marker(m.frame, m.track, result.x[0], result.x[1]))
     #select two keyframes
     #keyframes = self.selectKeyFrames(normalizedMarkers, K)
     kf1, kf2 = 0, Marker.getMaxFrame(normalizedMarkers)
     #Actual reconstruction
     keyframeMarkers = Marker.markersForTracksInBothFrames(markers, kf1, kf2)
     if len(keyframeMarkers) < 8:
         print('Error: Not Enough Keyframe Markers.')
         return None, None, None
     
     maxFrame = Marker.getMaxFrame(markers)
     maxTrack = Marker.getMaxTrack(markers)
     reconstruction = Reconstruction(maxFrame, maxTrack) 
     
     self.reconstructTwoFrames(keyframeMarkers, reconstruction)
     #TODO: EuclideanBundle(normalized_tracks)
     self.completeReconstruction(normalizedMarkers, reconstruction)        
     #TODO: EuclideanBundleCommonIntrinsics
     self.scaleToUnity(reconstruction)
     #TODO: EuclideanReprojectionError        
     return reconstruction.extract() # K is refined but not returned here
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--lexicon",
                        help="Specify the path of the lexical file.",
                        type=str)
    parser.add_argument("--document",
                        help="Specify the path of the input document.",
                        type=str)
    parser.add_argument("--output",
                        help="Specify the path of the output document.",
                        type=str)
    args = parser.parse_args()
    if args.lexicon is None or args.document is None or args.output is None:
        parser.print_help(sys.stderr)
        sys.exit(1)

    if not validate_input(args):
        print("Please enter valid paths for the inputs.")
        parser.print_help(sys.stderr)
        sys.exit(1)

    doc_reconstructor = Reconstruction(args.document, args.output,
                                       args.lexicon)
    doc_reconstructor.re_construct()
    parser.add_argument('--num_points',
                        type=int,
                        default=2048,
                        help='Num of points to use')
    parser.add_argument('--model_path',
                        type=str,
                        default='',
                        metavar='N',
                        help='Path to load model')
    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = get_parser()
    if args.eval == False:
        if args.task == 'reconstruct':
            reconstruction = Reconstruction(args)
            reconstruction.run()
        elif args.task == 'classify':
            classification = Classification(args)
            classification.run()
        elif args.task == 'segment':
            segmentation = Segmentation(args)
            segmentation.run()
    else:
        inference = Inference(args)
        feature_dir = inference.run()
        svm = SVM(feature_dir)
        svm.run()
Exemple #5
0
altitude3 = 59
wahrsis3 = Imager(name3, center3, radius3, relativePosition3, calibRot3,
                  calibTrans3, longitude3, lattitude3, altitude3)

name4 = 'wahrsis4'
center4 = [2000, 2975]
radius4 = 1665
relativePosition4 = np.array([-2.334, 101.3731, -8.04])
calibRot4 = np.array([[0.9710936, -0.23401871, 0.04703662],
                      [0.234924, 0.97190314, -0.01466276],
                      [-0.04228367, 0.02528894, 0.99878553]])
calibTrans4 = np.array([[-0.00274625], [-0.00316865], [0.00516088]])
wahrsis4 = Imager(name4, center4, radius4, relativePosition4, calibRot4,
                  calibTrans4)

images3 = [
    cv2.imread('wahrsis3/2015-10-29-12-58-01-wahrsis3-low.jpg'),
    cv2.imread('wahrsis3/2015-10-29-12-58-01-wahrsis3-med.jpg'),
    cv2.imread('wahrsis3/2015-10-29-12-58-01-wahrsis3-high.jpg')
]
images4 = [
    cv2.imread('wahrsis4/2015-10-29-12-58-01-wahrsis4-low.jpg'),
    cv2.imread('wahrsis4/2015-10-29-12-58-01-wahrsis4-med.jpg'),
    cv2.imread('wahrsis4/2015-10-29-12-58-01-wahrsis4-high.jpg')
]

reconst = Reconstruction(wahrsis3, wahrsis4,
                         datetime.datetime(2015, 10, 29, 12, 58, 1))
reconst.load_images(images3, images4)
reconst.process()
reconst.writeFigure("out.png")
from reconstruction import Reconstruction

pixel_height = 192
pixel_width = 256

if __name__ == '__main__':
    rec = Reconstruction(image_width=pixel_width,
                         image_height=pixel_height,
                         train_directory='test_imgs')
    print("End test")