Ejemplo n.º 1
0
def findretroreflectors():
    if not startupdone:
        return "Not online"
    pair = cam_control.prs.queue[0]
    shift = rd.getshift(pair[0].img, pair[1].img)
    out_img = rd.getblockmaxedimage(pair[1].img)
    done = rd.alignandsubtract(out_img, shift, pair[0].img)
    p = np.unravel_index(done.argmax(), done.shape)
    return "Location: %d %d" % p
Ejemplo n.º 2
0
    def analyse_image_pair(self,pair,save=True):
        searchbox = 100
        starttime = time.time()
        msg = ""
        msg += "Processing Images\n"
        msg += "time: %0.4f\n" % (time.time()-starttime)
        filename = "/home/pi/"+time.strftime("%Y%m%d_%H%M%S",time.gmtime(pair[0].time))+("%0.4f" % (pair[0].time%1))[1:]
        if save: np.save(filename,pair[0].img,allow_pickle=False)
        msg += "time: %0.4f\n" % (time.time()-starttime)
        msg += "Computing Shift\n"
        
        shift = rd.getshift(pair[0].img,pair[1].img,step=self.stepsize,searchbox=searchbox)
        msg += "    shift: %d %d\n" % (shift[0], shift[1])
        msg += "time: %0.4f\n" % (time.time()-starttime)
        msg += "Computing output non-flash blocked image\n"
        if not self.skipcalc:
            out_img = rd.getblockmaxedimage(pair[1].img,self.blocksize,self.offset)
        else:
            out_img = pair[1].img
            
        msg += "time: %0.4f\n" % (time.time()-starttime)
        
        if not self.skipcalc:
            msg+="Aligning and subtracting\n"
            done = rd.alignandsubtract(out_img,shift,pair[0].img)
            msg += "time: %0.4f\n" % (time.time()-starttime)
            
            maxvals = []
            for it in range(1):
                print(".")
                argmax = done.argmax()
                p = np.array(np.unravel_index(argmax, done.shape))
                maxval = done[p[0],p[1]]
                peak_sample_img = erase_around(done,p[0],p[1])
                score = score_img(peak_sample_img)
                p += searchbox
                if (p[0]>=done.shape[0]) or (p[1]>=done.shape[1]):
                    print("error (out of range) location")
                    msg+="  [error (out of range) location]\n"
                    continue #can't use this one
                
                maxvals.append({'val':maxval, 'location':p.copy(), 'sample_img':peak_sample_img,'score':score})
                msg += " - Preparing stats"
                msg += "peak at [%d, %d] = %d [score=%0.5f]\n" % (p[0],p[1],maxval,score)
                msg += ascii_draw(peak_sample_img)
                msg += "\n"
                msg += "time: %0.4f\n" % (time.time()-starttime)
             
            msg += "time: %0.4f\n" % (time.time()-starttime)                    
            lowresimages = []
            #print("Generating low res images")
            msg += " - Generating low res images\n"
            for img in [0,1]:
                #print("Image %d" % img)
                #lowresimages.append(pair[img].img[::10,::10].copy())
                if img==0:
                    lowresimages.append(pair[img].img[::10,::10].copy())
                    #lowresimages.append(rd.getblockmaxedimage(pair[img].img,10,1)[::10,::10])
                else:
                    #lowresimages.append(out_img[::10,::10].copy()) 
                    #lowresimages.append(None)
                    lowresimages.append(rd.shiftimg(out_img,shift,cval=255)[::10,::10].copy()) 
                #lowresimages.append(rd.getblockmaxedimage(pair[img].img)[::10,::10])
                msg += "time: %0.4f\n" % (time.time()-starttime)
                
        else:
            print("Skipping compute")
            maxvals = []
            lowresimages = []
            shift = [np.nan,np.nan]
            
        
        msg += "Computation Complete, recording\n"
        msg += "time: %0.4f\n" % (time.time()-starttime)                    
        print("Computation Complete, saving")  
        highresimages = []
        for img in [0,1]:
            im = pair[img].img
            if img == 1:
                im = rd.shiftimg(im,shift,cval=255)
            s = im.shape
            highresimages.append(im[int(s[0]/2-100):int(s[0]/2+100),int(s[1]/2-100):int(s[1]/2+100)].copy())
            
        #self.tracking_results.append({'lowresimages':lowresimages,'highresimages':highresimages,'maxvals':maxvals,'shift':shift})
        self.tracking_results.append({'lowresimages':lowresimages,'highresimages':highresimages,'maxvals':maxvals,'shift':shift})
         
        
        

        msg += "time: %0.4f\n" % (time.time()-starttime)    
            
        msg += "Recording Complete\n Returning Buffers\n"
        msg += "time: %0.4f\n" % (time.time()-starttime)    
        msg += "Buffers returned\n"            
        self.tracking_results[-1]['msg'] = msg
Ejemplo n.º 3
0
    def worker(self):
        import os
        os.nice(20) #these shouldn't be priorities
        searchbox = 100
        while True:
            #Awaiting image for processing [blocking]
            print("Waiting for image from camera control...(skipcalc=%d)" % self.skipcalc.value)
            pair = self.camera_queue.get()
            starttime = time.time()
            msg = ""

            msg += "Saving data:\n"
            msg += "time: %0.4f\n" % (time.time()-starttime)
            print(pair[0]['raw'])
            timestr = time.strftime("%Y%m%d_%H:%M:%S")
            np.save(open('raw_%s_0.np' % timestr,'wb'),pair[0]['raw'].astype(np.byte))
            msg += "time: %0.4f\n" % (time.time()-starttime)
            np.save(open('raw_%s_1.np' % timestr,'wb'),pair[1]['raw'].astype(np.byte))
            msg += "time: %0.4f\n" % (time.time()-starttime)
            msg += "Done\n"
            msg += "Processing Images\n"
            msg += "time: %0.4f\n" % (time.time()-starttime)
            msg += "Computing Shift (stepsize=%d)\n" % self.stepsize.value
            shift = rd.getshift(pair[0]['raw'],pair[1]['raw'],step=self.stepsize.value,searchbox=searchbox)
            msg += "    shift: %d %d\n" % (shift[0], shift[1])
            msg += "time: %0.4f\n" % (time.time()-starttime)
            msg += "Computing output non-flash blocked image\n"
            if not self.skipcalc.value:
                out_img = rd.getblockmaxedimage(pair[1]['raw'],self.blocksize.value,self.offset.value)
            else:
                out_img = pair[1]['raw']
                
            msg += "time: %0.4f\n" % (time.time()-starttime)
            
            if not self.skipcalc.value:
                msg+="Aligning and subtracting\n"
                start = np.array([self.startx.value,self.starty.value])
                end = np.array(out_img.shape)-np.array([self.endx.value,self.endy.value])
                
                done = rd.alignandsubtract(out_img,shift,pair[0]['raw'])#,start=start,end=end)
                msg += "time: %0.4f\n" % (time.time()-starttime)
                
                maxvals = []
                for it in range(self.searchcount.value):
                    #print(".")
                    argmax = done[start[0]-searchbox:end[0]-searchbox,start[1]-searchbox:end[1]-searchbox].argmax()
                    p = np.array(np.unravel_index(argmax, done.shape))
                    p+=start-searchbox
                    
                    maxval = done[p[0],p[1]]
                    peak_sample_img = erase_around(done,p[0],p[1])
                    score = score_img(peak_sample_img)
                    p += searchbox
                    if (p[0]>=done.shape[0]) or (p[1]>=done.shape[1]):
                        #print("error (out of range) location")
                        msg+="  [error (out of range) location]\n"
                        continue #can't use this one
                    
                    maxvals.append({'val':maxval, 'location':p.copy(), 'sample_img':peak_sample_img,'score':score})
                    msg += " - Preparing stats"
                    msg += "peak at [%d, %d] = %d [score=%0.5f]\n" % (p[0],p[1],maxval,score)
                    msg += ascii_draw(peak_sample_img)
                    msg += "\n"
                    msg += "time: %0.4f\n" % (time.time()-starttime)
                 
                msg += "time: %0.4f\n" % (time.time()-starttime)                    
                lowresimages = []
                #print("Generating low res images")
                msg += " - Generating low res images\n"
                for img in [0,1]:
                    #print("Image %d" % img)
                    #lowresimages.append(pair[img][::10,::10].copy())
                    if img==0:
                        im = pair[img]['raw'][::10,::10].copy()
                        
                        scalestart = (start/10).astype(int)
                        scaleend = (end/10).astype(int)
                        
                        im[scalestart[0],scalestart[1]:scaleend[1]] = 255
                        im[scaleend[0],scalestart[1]:scaleend[1]] = 255
                        lowresimages.append(im)
                    else:
                        im = rd.shiftimg(out_img,shift,cval=255)[::10,::10].copy()
                        lowresimages.append(im) 
                    msg += "time: %0.4f\n" % (time.time()-starttime)   
            else:
                maxvals = []
                lowresimages = []
                shift = [np.nan,np.nan]
                
            
            msg += "Computation Complete, recording\n"
            msg += "time: %0.4f\n" % (time.time()-starttime)                    

            highresimages = []
            for img in [0,1]:
                im = pair[img]['raw']
                if img == 1:
                    im = rd.shiftimg(im,shift,cval=255)
                s = im.shape
                highresimages.append(im[int(s[0]/2-100):int(s[0]/2+100),int(s[1]/2-100):int(s[1]/2+100)].copy())
            msg += "time: %0.4f\n" % (time.time()-starttime)
            msg += "datetime0: %s\n" % pair[0]['datetime'].strftime("%Y-%m-%dT%H:%M:%S.%f")
            msg += "datetime1: %s\n" % pair[1]['datetime'].strftime("%Y-%m-%dT%H:%M:%S.%f")
            #self.tracking_results.append({'lowresimages':lowresimages,'highresimages':highresimages,'maxvals':maxvals,'shift':shift})
            self.tracking_results_queue.put({'lowresimages':lowresimages,'highresimages':highresimages,'maxvals':maxvals,'shift':shift,'msg':msg,'dt0':pair[0]['datetime'].strftime("%Y-%m-%dT%H:%M:%S.%f"),'dt1':pair[1]['datetime'].strftime("%Y-%m-%dT%H:%M:%S.%f")})
             
            
            

            #msg += "time: %0.4f\n" % (time.time()-starttime)    
            #    
            #msg += "Recording Complete\n Returning Buffers\n"
            #pair = None #erase
#            pair[0].returnbuffer()
#            pair[1].returnbuffer()
            pair = None
            #msg += "time: %0.4f\n" % (time.time()-starttime)    
            #msg += "Buffers returned\n"            
            #self.tracking_results[-1]['msg'] = msg
            print("Processing Complete")