You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have done all the panel calibration etc and got the dls_correction from panel and DLS. I've worked through the Alignment.ipynb and wanted to replicate it for multiple flight_captures and it's not working. I pieced together all the code from Alignment.ipynb and added some minor modifications. I'd really appreciate if someone could tell me where I'm wrong. It's going through the captures and plotting the reflectance images but fails when it comes to alignment. Code below.
for cap1 in flight_captures:
cap1.plot_undistorted_reflectance(cap1.dls_irradiance()*dls_correction[0])
print("Aligning images. Depending on settings this can take from a few seconds to many minutes")
# Increase max_iterations to 1000+ for better results, but much longer runtimes
warp_matrices, alignment_pairs = imageutils.align_capture(cap1, max_iterations=200)
print("Finished Aligning, warp matrices:")
for i,mat in enumerate(warp_matrices):
print("Band {}:\n{}".format(i,mat))
dist_coeffs = []
cam_mats = []
# create lists of the distortion coefficients and camera matricies
for i,img in enumerate(cap1.images):
dist_coeffs.append(img.cv2_distortion_coeff())
cam_mats.append(img.cv2_camera_matrix())
# cropped_dimensions is of the form:
# (first column with overlapping pixels present in all images,
# first row with overlapping pixels present in all images,
# number of columns with overlapping pixels in all images,
# number of rows with overlapping pixels in all images )
cropped_dimensions = imageutils.find_crop_bounds(cap1.images[0].size(),
warp_matrices,
dist_coeffs,
cam_mats)
im_aligned = imageutils.aligned_capture(warp_matrices, alignment_pairs, cropped_dimensions)
# Create a normalized stack for viewing
im_display = np.zeros((im_aligned.shape[0],im_aligned.shape[1],5), dtype=np.float32 )
rows, cols, bands = im_display.shape
driver = gdal.GetDriverByName('GTiff')
fileno = 'test'+ '_' +'aligned' + '_' +j+'.tif'
j+1
outputImagePath = os.path.join('.','data', 'test_output')
outputImageName = os.path.join(outputImagePath, fileno)
print(outputImageName)
outRaster = driver.Create(**outputImageName**, cols, rows, bands, gdal.GDT_Float32)
for i in range(0,bands):
outband = outRaster.GetRasterBand(i+1)
outband.WriteArray(im_aligned[:,:,i])
outband.FlushCache()
outRaster = None
Error below
RuntimeError Traceback (most recent call last)
in ()
4 print("Aligning images. Depending on settings this can take from a few seconds to many minutes")
5 # Increase max_iterations to 1000+ for better results, but much longer runtimes
----> 6 warp_matrices, alignment_pairs = imageutils.align_capture(cap1, max_iterations=200)
7 print("Finished Aligning, warp matrices:")
8 for i,mat in enumerate(warp_matrices):
C:\imageprocessing-master\micasense\imageutils.py in align_capture(capture, ref_index, warp_mode, max_iterations, epsilon_threshold)
112
113 #required to work across linux/mac/windows, see https://stackoverflow.com/questions/47852237
--> 114 multiprocessing.set_start_method('spawn')
115 pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
116 for i,mat in enumerate(pool.imap_unordered(align, alignment_pairs)):
~\AppData\Local\Continuum\anaconda3\envs\micasense\lib\multiprocessing\context.py in set_start_method(self, method, force)
240 def set_start_method(self, method, force=False):
241 if self._actual_context is not None and not force:
--> 242 raise RuntimeError('context has already been set')
243 if method is None and force:
244 self._actual_context = None
RuntimeError: context has already been set
The text was updated successfully, but these errors were encountered:
Can only be called once in a program. Remove it from the alignment function and set it before you run other code so that it's not in a loop. See also the previous issue which also encountered this.
I have done all the panel calibration etc and got the dls_correction from panel and DLS. I've worked through the Alignment.ipynb and wanted to replicate it for multiple flight_captures and it's not working. I pieced together all the code from Alignment.ipynb and added some minor modifications. I'd really appreciate if someone could tell me where I'm wrong. It's going through the captures and plotting the reflectance images but fails when it comes to alignment. Code below.
for cap1 in flight_captures:
cap1.plot_undistorted_reflectance(cap1.dls_irradiance()*dls_correction[0])
print("Aligning images. Depending on settings this can take from a few seconds to many minutes")
Error below
RuntimeError Traceback (most recent call last)
in ()
4 print("Aligning images. Depending on settings this can take from a few seconds to many minutes")
5 # Increase max_iterations to 1000+ for better results, but much longer runtimes
----> 6 warp_matrices, alignment_pairs = imageutils.align_capture(cap1, max_iterations=200)
7 print("Finished Aligning, warp matrices:")
8 for i,mat in enumerate(warp_matrices):
C:\imageprocessing-master\micasense\imageutils.py in align_capture(capture, ref_index, warp_mode, max_iterations, epsilon_threshold)
112
113 #required to work across linux/mac/windows, see https://stackoverflow.com/questions/47852237
--> 114 multiprocessing.set_start_method('spawn')
115 pool = multiprocessing.Pool(processes=multiprocessing.cpu_count())
116 for i,mat in enumerate(pool.imap_unordered(align, alignment_pairs)):
~\AppData\Local\Continuum\anaconda3\envs\micasense\lib\multiprocessing\context.py in set_start_method(self, method, force)
240 def set_start_method(self, method, force=False):
241 if self._actual_context is not None and not force:
--> 242 raise RuntimeError('context has already been set')
243 if method is None and force:
244 self._actual_context = None
RuntimeError: context has already been set
The text was updated successfully, but these errors were encountered: