Browse Source

Arrumando marcador

capellaresumo 6 years ago
parent
commit
e2c4c3002d
4 changed files with 14 additions and 23 deletions
  1. 1 1
      cmarkers.py
  2. BIN
      lejos/Con.nxj
  3. 13 22
      main.py
  4. 0 0
      marker_images/gem-cmarkers.py

+ 1 - 1
cmarkers.py

@@ -117,7 +117,7 @@ def getCMarkers (img):
                         markers.append([number, mid, angle])
     
     img2 = cv2.drawKeypoints(img2, kk, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
-    cv2.imshow("m3", img2)
+    # cv2.imshow("m3", img2)
     return markers
 
 def getNumber(img, threshold):

BIN
lejos/Con.nxj


+ 13 - 22
server.py → main.py

@@ -9,19 +9,13 @@ import time
 import numpy as np
 import os
 from cmarkers import getCMarkers, get_transform_matrix_points
- 
-##
-# Opens a video capture device with a resolution of 800x600
-# at 30 FPS.
-##
+
+# open camera
 def open_camera(cam_id = 1):
     cap = cv2.VideoCapture(cam_id)
     return cap
  
-##
-# Gets a frame from an open video device, or returns None
-# if the capture could not be made.
-##
+# get frame
 def get_frame(device):
     ret, img = device.read()
     if (ret == False): # failed to capture
@@ -29,16 +23,13 @@ def get_frame(device):
         return None
     return img
  
-##
-# Closes all OpenCV windows and releases video capture device
-# before exit.
-##
+# close camera
 def cleanup(cam_id = 0): 
     cv2.destroyAllWindows()
     cv2.VideoCapture(cam_id).release()
 
 
-# Global variable containing the 4 points selected by the user in the corners of the board
+# 4 points selected by the user in the corners of the board
 corner_point_list = []
  
 ##
@@ -115,7 +106,8 @@ def get_transform_matrix(dev, board_size, dpi, calib_file = None):
  
         # dest is a list of where these 4 points should be located on the
         # rectangular board (in the same order):
-        dest = np.array( [ (0, 0), (0, board_size[1]*dpi), (board_size[0]*dpi, 0), (board_size[0]*dpi, board_size[1]*dpi) ], np.float32)
+        a = [ (0, 0), (0, board_size[1]*dpi), (board_size[0]*dpi, 0), (board_size[0]*dpi, board_size[1]*dpi) ]
+        dest = np.array(a, np.float32)
         print(corner_point_list)
         # Calculate the perspective transform matrix
         trans = cv2.getPerspectiveTransform(src, dest)
@@ -127,9 +119,6 @@ def get_transform_matrix(dev, board_size, dpi, calib_file = None):
     else:
         return None
 
-
-##################################################### 
-### Calibration Example ###
 if __name__ == "__main__":
     parser = argparse.ArgumentParser()
     cam_id = 1
@@ -150,8 +139,10 @@ if __name__ == "__main__":
  
     # The size of the board in inches, measured between the two
     # robot boundaries:
-    board_size = [215, 185]
+    board_size = [185, 215]
     point = []
+    if camera:
+        board_size = [board_size[1], board_size[0]]
  
     # Number of pixels to display per inch in the final transformed image. This
     # was selected somewhat arbitrarily (I chose 17 because it fit on my screen):
@@ -173,13 +164,12 @@ if __name__ == "__main__":
         if camera:
             img_orig = get_frame(dev)
         else:
-            time.sleep(0.5)
+            time.sleep(0.1)
 
         start = time.time()
         if img_orig is not None: # if we did get an image
             img = img_orig
             if camera:
-
                 img = cv2.warpPerspective(img_orig, transform, dsize=transform_size)
                 e1 = cv2.getTickCount()
                 # your code execution
@@ -210,7 +200,8 @@ if __name__ == "__main__":
             seconds = end - start
             fps  = 1.0 / seconds
             start = time.time()
-            cv2.putText(img, str(fps), (0,60), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255))
+            if camera:
+                cv2.putText(img, str(fps), (0,60), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255))
             res = img
             cv2.imshow("warped", res)
  

+ 0 - 0
gem-cmarkers.py → marker_images/gem-cmarkers.py