Hello, I’m a newly in all OpenMV.
Have been working on a 6 axis robot arm project and did like to integrate OpenMV as vision system to detect parts orientation at random. The Robot controller program is looking in a txt file located on the C drive for the coordinates, X, Y, and rotation.
So far I found the Single Color Code Tracking Example quite helpful, from there I need to send or save the x, y, rotation to a txt file that the robot software reads and then is able to pick the part accordingly, it could also be save to the sd card inside the camera.
I have not been able to find any example that would show me how I would save or write the txt file to sd or external drive. Any help would be very appreciated. See code bellow:
# # Single Color Code Tracking Example # # This example shows off single color code tracking using the OpenMV Cam. # # A color code is a blob composed of two or more colors. The example below will # only track colored objects which have both the colors below in them. import sensor, image, time from pyb import LED # Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max) # The below thresholds track in general red/green things. You may wish to tune them... #thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds -> index is 0 so code == (1 << 0) # (30, 100, -64, -8, -32, 32)] # generic_green_thresholds -> index is 1 so code == (1 << 1) thresholds = [(55, 100,-24, 11, 32, 86), #1#yellow (27, 100, 42, 80, 30, 64), #2#red (39, 100,-51,-12, 10, 57)] #4#green # Codes are or'ed together when "merge=True" for "find_blobs". sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # must be turned off for color tracking clock = time.clock() object_x_old = 0 object_y_old = 0 code = 2 ## 1:yellow 2:red 4:green buf = "00" # Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are # returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the # camera resolution. "merge=True" must be set to merge overlapping color blobs for color codes. while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs(thresholds, pixels_threshold=100, area_threshold=100, merge=False): #check if there is object with right color if blob.code() == code: img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) print(blob.cx(), blob.cy(),blob.w()) #make sure the detected object is stable and print the coordinates #first it detect if the coordinates of blob is available #second compared with the last position to make sure if the object is not moving #third reduce the affect of anbience if blob.cx()!=None and ( abs(object_x_old - int(blob.cx())) < 8 and abs(object_y_old - int(blob.cy())) < 8) and ( blob.w()>35 and blob.h()>35): print("stable!") if buf==ord('S') : #clear the flag buf = "00"