def normalise(self, i_ipl_image):
     #Do the affine transform
     if self.__rot_mat == None:
         warped_image = i_ipl_image
     else:
         warped_image = cv.cvCreateImage(
             cv.cvSize(i_ipl_image.width, i_ipl_image.height), 8, 1)
         cv.cvWarpAffine(i_ipl_image, warped_image, self.__rot_mat)
     #Crop
     if self.__roi == None:
         self.__cropped_image = warped_image
     else:
         self.crop(warped_image)
     #Scale
     if self.__resize_scale == 1:
         scaled_image = self.__cropped_image
     else:
         w = int(round(self.__cropped_image.width * self.__resize_scale))
         h = int(round(self.__cropped_image.height * self.__resize_scale))
         scaled_image = cv.cvCreateImage(cv.cvSize(w, h), 8, 1)
         cv.cvResize(self.__cropped_image, scaled_image, cv.CV_INTER_LINEAR)
     #Histogram equalisation
     if self.__equalise_hist:
         cv.cvEqualizeHist(scaled_image, scaled_image)
     #Blur
     if self.__filter_size == 0:
         smoothed_image = scaled_image
     else:
         smoothed_image = cv.cvCreateImage(
             cv.cvSize(scaled_image.width, scaled_image.height), 8, 1)
         cv.cvSmooth(scaled_image, smoothed_image, cv.CV_GAUSSIAN,
                     self.__filter_size)
     return smoothed_image
 def normalise(self, i_ipl_image):
     #Do the affine transform
     if self.__rot_mat == None:
         warped_image = i_ipl_image
     else:
         warped_image = cv.cvCreateImage(cv.cvSize(i_ipl_image.width,i_ipl_image.height), 8, 1)
         cv.cvWarpAffine(i_ipl_image , warped_image,  self.__rot_mat );
     #Crop
     if self.__roi == None:
         self.__cropped_image = warped_image
     else:
         self.crop(warped_image)
     #Scale
     if  self.__resize_scale == 1:
         scaled_image = self.__cropped_image
     else: 
         w = int(round( self.__cropped_image.width * self.__resize_scale))
         h = int(round( self.__cropped_image.height * self.__resize_scale))
         scaled_image = cv.cvCreateImage(cv.cvSize(w, h), 8, 1)
         cv.cvResize( self.__cropped_image, scaled_image ,cv.CV_INTER_LINEAR)
     #Histogram equalisation
     if self.__equalise_hist: 
         cv.cvEqualizeHist(scaled_image,scaled_image)
     #Blur
     if self.__filter_size == 0: 
         smoothed_image = scaled_image
     else: 
         smoothed_image = cv.cvCreateImage(cv.cvSize(scaled_image.width, scaled_image.height), 8, 1)
         cv.cvSmooth(scaled_image, smoothed_image, cv.CV_GAUSSIAN, self.__filter_size)
     return smoothed_image
Beispiel #3
0
      screen.fill(white)
      queryWebcam()
      if time.time() > timer + 0.5:
        switchMode(MODE_DETECT_OBSTACLES2)
    elif mode == MODE_DETECT_OBSTACLES3:
      screen.fill(white)
      queryWebcam()
      if time.time() > timer + 0.5:
        action = ""
        switchMode(MODE_READY)
    elif mode == MODE_DETECT_OBSTACLES2:
      before = time.time()
      screen.fill(white)
      im = queryWebcam()
      opencv.cvCvtColor (im, igray, opencv.CV_BGR2GRAY)
      opencv.cvSmooth(igray, igray, opencv.CV_GAUSSIAN, 3, 3)
      opencv.cvAdaptiveThreshold(igray, iwhite, 255, opencv.CV_ADAPTIVE_THRESH_GAUSSIAN_C)
      num, contours = opencv.cvFindContours (iwhite, stor, opencv.sizeof_CvContour, opencv.CV_RETR_LIST)
  
      opencv.cvCvtColor(iwhite, im, opencv.CV_GRAY2BGR)
      staticImage = im

      retrieveObstacles(contours)
      switchMode(MODE_DETECT_OBSTACLES3)
      action = "Detection took: %.2f" % (time.time()-before)

    elif mode == MODE_READY:
      screen.fill(lgray)
      im  = queryWebcam()
      opencv.cvCvtColor(im, igray, opencv.CV_BGR2GRAY)
      opencv.cvSmooth(igray, igray, opencv.CV_GAUSSIAN, 5, 5)