#garfield Logs
Nov 24 2022
#garfield Calendar
12:58 AM Tom_L: AP203 or AP214 step format?
01:08 AM rue_mohr: heh
01:08 AM rue_mohr: its for all the plastic bits of the sensor I made up
01:08 AM Tom_L: sw will convert
01:08 AM Tom_L: how many parts?
01:08 AM rue_mohr: I wouldn't want to trouble you, I really dont think anyone ever builts the stuff anyhow
01:08 AM Tom_L: got gitcommit & gitpush somewhat working
01:08 AM Tom_L: been a sore spot for a couple weeks
01:08 AM rue_mohr: so what was hanging it up?
01:08 AM Tom_L: mostly authentication
01:08 AM Tom_L: and lack of knowledge
01:08 AM rue_mohr: was it running as a funny user?
01:08 AM Tom_L: i need git add on a few files before it will go smooth
01:08 AM Tom_L: it wasn't running at all
01:08 AM rue_mohr: heh
01:08 AM Tom_L: back to the git repo
01:08 AM Tom_L: it would build successfully locally
01:08 AM Tom_L: but i wanted to push a deb back to the repo
01:16 AM rue_mohr: gnight
02:47 AM rue_mohr: polprog, you sleeping in?
09:19 AM rue_mohr: 3458
09:19 AM rue_mohr: missed a cool number by 2...
11:07 AM aandrew: ooh, amazon basics metal rulers... $9 for four and they have 0.5mm markings
11:08 AM aandrew: one of those is getting chopped up for the gear thing. I've called that box "cogswell" :-)
11:48 AM rue_mohr: :)
11:56 AM rue_mohr: oh I got the pi running and stuck it in the shop, on the stand, looking at a gear
12:06 PM rue_mohr: https://pbs.twimg.com/media/FiUYvLxXoAAfFmc?format=jpg&name=large
12:06 PM rue_mohr: so, they set up 32 bits of address, but only use 24
12:06 PM rue_mohr: WHY
12:06 PM rue_mohr: and then the write data bus is seperate from the read data bus
12:07 PM rue_mohr: there is a read strobe, but no write strobe
12:07 PM rue_mohr: what is write mask!? and why is it 4 bits
12:08 PM rue_mohr: maybe wmask is write strobe, but in 4 seperate bits so you can select the byte being written
12:08 PM rue_mohr: and it cant write 32 bits
12:08 PM rue_mohr: at most, 16
12:09 PM rue_mohr: so why is the bus 32 bits?
12:10 PM Tom_L: is the bookworm img working for you?
12:11 PM rue_mohr: I only booted up the newer one so far
12:11 PM rue_mohr: I'm behind on my homework
12:14 PM rue_mohr: I cant find the text source for that image....
12:14 PM rue_mohr: i'm not sure if my ability to focus on a project is any worse with the introduction of twitter
12:15 PM rue_mohr: eee gad 3461
12:16 PM rue_mohr: I have to say tho, tiwtter is offering some great distractions
12:42 PM rue_mohr: I best make sure I get _something_ done today
12:56 PM aandrew: rue_mohr> and then the write data bus is seperate from the read data bus
12:56 PM aandrew: easier to implement in logic
12:56 PM aandrew: no need for gigantic MUX that steals resources that could be used for other things
12:57 PM aandrew: in fact you could probably reduce it and have the RV32 use an 8-bit bus at the cost of more cycles per clock
12:57 PM aandrew: the biggest barrier to really "grokking" FPGAs is letting go of a lot of the things that make perfect sense in software or even OTS logic
12:58 PM aandrew: hence the "one hot" design for bit masks or the concept of always having both logic paths defined rather than having a default and overriding it if a condition is true
12:59 PM aandrew: I don't know about you guys but to me, twitter has gotten a lot better since Musk took it over. The tech content is way more easy to find and ads are way less. :-)
01:02 PM rue_mohr: with the chips I have, the memory would have to be external
01:02 PM rue_mohr: I think I can implement that 1 bit on that cpld I set up on the dip40
01:04 PM aandrew: that's unfortunate; not needing external foo is one of hte big plusses.
01:04 PM aandrew: although I guess one of your first modules could be a SPI master. :-)
01:04 PM rue_mohr: it would be ok with me, as it would kinda make it like a generic microprocessor
01:15 PM rue_shop3: the dip I put the cpld on is a 9536
01:15 PM rue_shop3: I wonder if its big enough
01:17 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
01:17 PM rue_shop3: pretty good image
01:25 PM rue_shop3: edge light!
01:26 PM rue_shop3: wow not as good a pickup as I'd have expected
01:27 PM rue_shop3: huh
01:30 PM rue_shop3: no I dont think that is helping...
01:31 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
01:31 PM rue_shop3: hmmm
01:34 PM rue_shop3: ok, I'll make that the test image
01:45 PM aandrew: yep looks like a good pic
01:56 PM rue_mohr: eeek
01:56 PM rue_mohr: opencv is not just one package
01:58 PM rue_mohr: https://learnopencv.com/getting-started-with-opencv/
02:00 PM rue_mohr: I suppose I start with getting it to read the jpg?
02:00 PM rue_mohr: then maybe thresholding?
02:01 PM rue_mohr: c++ is a mess, how about using python?
02:01 PM rue_mohr: which is like walking around with two toolboxes strapped to your feet, but atleast you can walk
02:02 PM rue_mohr: unlike c++, which cuts your leg off and tells you your robotic leg is on backorder, call back later
02:03 PM rue_mohr: python3-opencv
02:08 PM rue_mohr: ok, version issue
02:08 PM rue_mohr: how new is opencv2?
02:10 PM rue_mohr: oph I have to specifically run python3
02:11 PM rue_mohr: ok
02:11 PM rue_mohr: achieved flashing led!
02:12 PM rue_mohr: https://learnopencv.com/read-display-and-write-an-image-using-opencv/
02:23 PM rue_mohr: building a new keyboard might be a good long term investment project
02:23 PM rue_mohr: this keyboard is just about done
02:23 PM rue_mohr: you know, where the sliders are jambing up and you almost have to use a pickaxe to get them to register?
02:25 PM rue_mohr: its hard to find a keyboard thats not 8x larger than the key field
02:41 PM aandrew: I just use the python ai
02:41 PM aandrew: api
02:41 PM rue_mohr: isnt' that what that is?
02:41 PM aandrew: yep
02:41 PM aandrew: I was talking about ignoring the C++ one
02:41 PM rue_mohr: ok
02:42 PM rue_mohr: I have c++ source just a few years old that wont compile because of changes to c++ libraries or compiler or something
02:42 PM rue_mohr: I have C source from the beggining of time that compiles ok
02:42 PM aandrew: I was taking the approach of using the built in contour support
02:42 PM aandrew: soething like
02:42 PM aandrew: im = cv.imread('test.jpg')
02:42 PM aandrew: imgray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
02:42 PM aandrew: ret, thresh = cv.threshold(imgray, 127, 255, 0)
02:42 PM aandrew: im2, contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
02:46 PM rue_mohr: https://learnopencv.com/contour-detection-using-opencv-python-c/ <- I didn't playw ith this yet
02:46 PM rue_mohr: provided that all works, we do a "find circle" ? and use the middle to try to draw a circular threshold to count teeth?
02:48 PM aandrew: nice, some despeckling and thresholding and the easy part will be done: https://ibb.co/84vWfbm
02:48 PM rue_mohr: is that image ...huge?
02:49 PM rue_mohr: huh, didn't catch the inner edges
02:51 PM rue_mohr: I have to set up a for sale sign and get a bill to someone, stand by
02:51 PM rue_mohr: but dont hold up for me
02:55 PM Tom_L: yay i think i got the bot working
02:55 PM rue_mohr: :]
02:55 PM Tom_L: at least it's not spouting off when it shouldn't now
02:58 PM Tom_L: spoke too soon..
03:07 PM rue_mohr: aandrew, ok, just trying to quickly catch up
03:08 PM rue_mohr: http://ruemohr.org/~ircjunk/tempimage/contours_none_image1.jpg
04:18 PM aandrew: wow nice
04:40 PM rue_mohr: ok, I made the tool to put the tie down eyes on the cat awning tarp
05:09 PM aandrew: you're more productive than I am
05:31 PM rue_shop3: I spend a lot of time sitting in a chair with my eyes spinning around not doing anything
05:33 PM rue_mohr: but I got the awnind finished and the shed for sale sign put up
05:33 PM rue_mohr: I got it just the right height too, I cant see it from the desk
05:37 PM aandrew: you've got vertigo?
05:41 PM rue_mohr: yes and no
07:13 PM rue_mohr: I could get the camera a lot closer tho
07:14 PM rue_mohr: I forgot which two of us wanted to use this
07:39 PM aandrew: heh
07:40 PM rue_mohr: I dont know how the focus on the camera I have works
07:40 PM rue_mohr: I think its a pinhole
07:40 PM rue_mohr: as so, always focused
07:41 PM aandrew: https://ibb.co/x2Mpwxq is what I've got now
07:41 PM aandrew: tryign to think about how to do this
07:41 PM aandrew: I was going to fit two circles, one for the outside of the teeth, the other for the inside
07:41 PM rue_mohr: set of a circle half way, then use a geofence to find out how many times if crosses?
07:41 PM aandrew: mine I had to crack the nail polish type stuff off and rotate it
07:41 PM aandrew: it's not perfect yet but close
07:42 PM rue_mohr: what did you tweak to get it that good?
07:42 PM aandrew: rue_mohr: yeah a third circle whose diameter is halfway between the first two would give a nice reference to "walk" and count crossings, divide by 2 and there's number of teeth
07:42 PM aandrew: I'm just screwing around really
07:43 PM rue_mohr: its working
07:43 PM aandrew: imgray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
07:43 PM aandrew: blur = cv.GaussianBlur(imgray, (15, 15), 0)
07:43 PM aandrew: ret, thresh = cv.threshold(blur, 127, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C + cv.THRESH_OTSU)
07:43 PM aandrew: contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
07:43 PM aandrew: I'm letting cv do the hard work (gaussian blur and adaptive thresholding)
07:43 PM aandrew: and then the findcontours I was going to try to get a little smarter with to try to identify only the gear
07:43 PM aandrew: it's real stupid right now
07:44 PM aandrew: # ic = interesting contours
07:44 PM aandrew: # try to find the outside contour of the gear, ignoring the ruler and (for now anyway) the axle hole
07:44 PM rue_mohr: I'm sure there is a 'find circles' in opencv
07:44 PM aandrew: ic = []
07:44 PM aandrew: for c in contours:
07:44 PM aandrew: (x, y, w, h) = cv.boundingRect(c)
07:44 PM aandrew: if x > new_width and w > new_width and h > new_height:
07:44 PM aandrew: ic.append(c)
07:44 PM aandrew: print(ic)
07:44 PM aandrew: cv.drawContours(img, ic, -1, (0,0,255), 3)
07:44 PM aandrew: there is
07:44 PM aandrew: the trick is trying to get it to find the right diameter for the inner gears
07:44 PM rue_mohr: I dont know how it would do on the gear
07:45 PM aandrew: er what I mean to find the interior (minimum)
07:45 PM rue_mohr: honestly, even I might not notice there was one in that image
07:45 PM aandrew: I think the outer should be easy
07:45 PM aandrew: the inner I think might be an iterative process
07:45 PM aandrew: well the outline is overlaid on the original image, not wht it's working in
07:45 PM aandrew: on
07:45 PM rue_mohr: I wonder if there is a 'geofence' in opencv
07:46 PM rue_mohr: "the dog is in the garden" kinda thing
07:47 PM aandrew: https://ibb.co/4MFzb9r is what the algo is working on, that is the threshold image
07:47 PM aandrew: from cv.threshold() above
07:47 PM aandrew: the LED ring is working better too, got things tidier
07:48 PM rue_mohr: I was surprised when I did that outline that there are not as many pixels in the image as I thought
07:48 PM rue_mohr: you have the camera lens ring type thing?
07:49 PM aandrew: actually I could use circularity to do blob detection
07:49 PM aandrew: I have a tiny (8 LED) WS2812 LED ring
07:49 PM aandrew: it's sitting directly under the camera (the camera is looking "through" the middle of it)
07:50 PM aandrew: I can turn on any of the LEDs to any colour/intensity to try to get better images or detect things like the inner gear
07:50 PM aandrew: at least in theory
07:50 PM rue_mohr: my camera is actually sitting ON the plexiglass shelf
07:55 PM rue_mohr: huh, the program could save the gear in a database for ya, give you a UID sticker to put on it
07:55 PM aandrew: heh yes it could
07:55 PM rue_mohr: you could sort by tooth count and pitch
07:55 PM aandrew: or let's get a fiber laser and burn the QR code right on it
07:56 PM rue_mohr: hmm
07:56 PM rue_mohr: all my gears could be cataloged in about a day
07:56 PM rue_mohr: well
07:57 PM rue_mohr: this wouldn't do well on the slanted pitch ones
07:57 PM rue_mohr: hmm
08:08 PM aandrew: yeah the outer is easy: https://ibb.co/0CnTFf5
08:08 PM aandrew: the goal isn't to do 100%, but if it can hit 80% of the stock that'd certainly make a big dent in the pile
08:42 PM rue_mohr: why is there this steady trickle of new followers on twitter!?
08:43 PM rue_mohr: twitter has started to have a negative impact on me getting things done
08:43 PM rue_mohr: hmm, actually I wonder
08:43 PM rue_mohr: I started using it to encourage me to get doing things again
08:44 PM rue_mohr: maybe without it I wouldn't be working on much of anything
08:52 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
08:52 PM rue_shop3: hmm
08:52 PM rue_shop3: starts to get blurry
09:05 PM rue_shop3: aandrew, I have an idea
09:05 PM rue_shop3: what do they do in the movies to remove the background };]
09:06 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
09:17 PM rue_shop3: your not going to pick up on the link fast enough
09:18 PM rue_shop3: and I think I need a bigger hole in my diffusor
09:38 PM rue_shop3: is asking for a diffusor to diffuse more like asking for a more random random?
09:41 PM rue_shop3: ok I'll go with that
09:42 PM rue_shop3: lets see if I can learn how to use opencv to do removal of that now
09:42 PM aandrew: wow
09:42 PM aandrew: https://ibb.co/HVwKfy1
09:42 PM aandrew: getting closer
09:42 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
09:43 PM rue_shop3: what do you think
09:43 PM aandrew: what are you doing there
09:43 PM aandrew: it looks out of focus
09:43 PM rue_shop3: yea, but greenscreen removal
09:43 PM rue_shop3: ?
09:44 PM rue_shop3: less input noise?
09:44 PM aandrew: https://ibb.co/SvhmfDt
09:45 PM aandrew: I think the opencv edge detection is working really well, I don't think we need to try to do it "analogue" by using a chroma key approach
09:49 PM rue_shop3: oops I shouldn't have tried to adjust the focus
09:50 PM rue_shop3: oops I shouldn't have tried to adjust the focus
09:51 PM rue_shop3: ok, I thnk its ok
09:54 PM rue_shop3: http://ruemohr.org/%7Eircjunk/tempimage/foo.jpg
09:54 PM rue_shop3: ok
09:55 PM aandrew: hahaha
09:55 PM aandrew: https://ibb.co/Ksgkv21
09:55 PM aandrew: not sure what happened there
09:55 PM aandrew: it did not compute the contour correctly
09:55 PM aandrew: could be my stupid simple "find the gear" method though
09:56 PM aandrew: it's not very robust
09:57 PM rue_mohr: haa
10:00 PM rue_mohr: I noticed the thresholding is really sensitive to the background
10:08 PM aandrew: yeah that's why I was using the more advanced autothresholding
10:08 PM aandrew: and my idea of looking for the most "runs" of common points looks a little better
10:08 PM aandrew: but it also shows the "find the center of the gear" isn't working quite perfectly
10:08 PM aandrew: but this is also probably WAY more than good
10:09 PM aandrew: https://ibb.co/VCbtGLT
10:10 PM rue_mohr: http://ruemohr.org/~ircjunk/tempimage/image_thres1.jpg
10:10 PM rue_mohr: this is my greenscreen mask
10:10 PM rue_mohr: hmmm
10:10 PM rue_mohr: so
10:11 PM rue_mohr: so your working out the circle based on a bounding rect?
10:13 PM aandrew: no
10:13 PM aandrew: I'm letting opencv do it since I"m stupid
10:14 PM aandrew: oc_center, oc_radius = cv.minEnclosingCircle(ic[0])
10:14 PM rue_mohr: findcircle?
10:14 PM rue_mohr: oooo
10:14 PM aandrew: then I start there and go to radius 1, drawing circles and counting how many common points that test circle has with the gear
10:14 PM aandrew: that's how I find the minimum circle
10:15 PM aandrew: (minmum for the gear I mean)
10:19 PM rue_mohr: I'll try to go down a bit of a different road for the hell of it
10:19 PM rue_mohr: but your definitly winning so far
10:19 PM rue_mohr: :)
10:19 PM aandrew: well I haven't got to the hard part yet, that's where I usually lose interest because real life gets in the way
10:19 PM rue_mohr: heh
10:20 PM rue_mohr: thats why I had to finish that resolver that night
10:20 PM aandrew: I want to look for the ruler, find the 0.5mm distance and actually give measurements
10:20 PM rue_mohr: how about just precal it?
10:28 PM aandrew: hmm apparently I can't count
10:28 PM aandrew: precalculate it? where is the fun in that??
10:29 PM rue_mohr: heh
10:29 PM rue_mohr: you know, with a fixed speed motor and a flapper a machine could count the teeth :]
10:29 PM rue_mohr: hahah
10:29 PM rue_mohr: before 1 turn even
10:33 PM aandrew: https://ibb.co/z6N0Pwv
10:33 PM aandrew: why in the hell is that only counting 24 crossings?!
10:33 PM aandrew: heh yes that is true
10:34 PM rue_mohr: so yours is 28, ok
10:34 PM rue_mohr: your for sure using the white circle?
10:34 PM rue_mohr: blue would miss some
10:34 PM aandrew: yep I'm pretty sure
10:35 PM rue_mohr: I'm glad this isn't a project I need to hand in by 10:00 tommorow morning
10:35 PM rue_mohr: :]
10:35 PM aandrew: # now that we know where the teeth are, draw a circle halfway between the min/max and count the number of crossings.
10:36 PM aandrew: # half of the number of crossings should be the number of teeth
10:36 PM aandrew: mid_tooth_radius = oc_radius_int - (oc_radius_int - ic_radius_best) // 2
10:36 PM aandrew: count_circle = np.zeros(thresh.shape, dtype=np.uint8)
10:36 PM aandrew: cv.circle(count_circle, oc_center_int, mid_tooth_radius, (255,255,255), 1)
10:36 PM aandrew: count_contour, _ = cv.findContours(count_circle, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE)
10:36 PM aandrew: num_crossings = 0
10:36 PM aandrew: in_run = False
10:36 PM aandrew: for p in count_contour[0]:
10:36 PM aandrew: # if this point is on the gear and the last point wasn't, ++tooth
10:36 PM aandrew: if cv.pointPolygonTest(ic[0], (float(p[0][0]), float(p[0][1])), False) == 0:
10:36 PM aandrew: # we weren't "on" the gear before, but we are now
10:36 PM aandrew:
10:36 PM aandrew: print(f"max tooth radius at {oc_radius_int}, min tooth radius at {ic_radius_best}, center of gear at {oc_center_int}, found {num_crossings} crossings")
10:36 PM aandrew: I wonder if the CHAIN_APPROX_SIMPLE is causing trouble, but I doubt it
10:37 PM aandrew: oh wait
10:37 PM aandrew: you're missing half my code
10:38 PM aandrew: https://pastebin.com/y45ps60M
10:39 PM aandrew: yep that was it
10:39 PM aandrew: it's still off now, now by too many
10:40 PM aandrew: heh
10:40 PM aandrew: I went from 24 crossings to 52 to now 42
10:40 PM rue_mohr: 42 will do for the night?
10:41 PM aandrew: I need 56
10:41 PM rue_mohr: is the trae a vector?
10:41 PM aandrew: is the what?
10:41 PM rue_mohr: you have the middle of the gear ok right?
10:41 PM rue_mohr: when it contours it
10:41 PM rue_mohr: isn't that a vector?
10:42 PM rue_mohr: is that a vector you can change from a cartesian to a polar?
10:42 PM aandrew: You're very quickly exhausting my knowledge of opencv
10:43 PM aandrew: the countours are an array of points which define the shape
10:43 PM rue_mohr: then take the variation in r and amplify it, then measure the frequency
10:43 PM aandrew: ooh
10:43 PM rue_mohr: I know nothing
10:43 PM aandrew: I should try approximating it
10:50 PM aandrew: ok I see the issue but I'm not sure how to solve it
10:50 PM aandrew: the polygon LOOKS solid but it isn't
10:51 PM rue_mohr: cartesian to polar?
10:52 PM aandrew: not that I'm aware of
10:52 PM aandrew: oh maybe I need to draw lines
11:07 PM rue_mohr: "cy +-3 and stating that the curve must be closed."
11:07 PM rue_mohr: https://docs.opencv.org/3.4/da/d0c/tutorial_bounding_rects_circles.html
11:07 PM rue_mohr: ?
11:15 PM rue_mohr: heh
11:16 PM rue_mohr: make a mask to the white circle
11:16 PM rue_mohr: filled
11:16 PM rue_mohr: subtract it from the gear mask
11:16 PM rue_mohr: then count the blobs that remain
11:16 PM rue_mohr: after having the contours one find them again
11:25 PM aandrew: number of intersection contours: 56
11:25 PM aandrew: !!!
11:26 PM rue_mohr: heh, how stable is it!!!
11:26 PM rue_mohr: since you have done that, I worked out how to blank an image
11:29 PM rue_mohr: oh hello
11:29 PM rue_mohr: oh
11:32 PM rue_mohr: oh I see, it fits the shapes for each contour
11:36 PM rue_mohr: how did you ditch the hole?
11:42 PM rue_mohr: http://ruemohr.org/~ircjunk/tempimage/image_thres1.jpg
11:42 PM rue_mohr: I think I'll try checking the sound of them and ditch them if they dont sound like gear teeth
11:43 PM rue_mohr: not quite sure how, but I have a notion
11:44 PM rue_mohr: oh, supper
11:44 PM rue_mohr: I need a machine to start the supper machine
11:45 PM rue_mohr: this could get out of hand
11:46 PM rue_mohr: rice or potato?
11:48 PM rue_mohr: ok, polygon, you must be an array of vectors
11:48 PM rue_mohr: how do I know your polar amplitude....