So to cut a long story short you have a large image Blob.jpg and two smaller images bot.png and target.png? You move each small image over the larger image to find the best or sufficient match?
An image is simply an array of numbers so it would look something like this:
To enlarge image below right click image and choose Open link in new window.
I would have to look up the cv documentation to understand the "methods".
Python is new to me and indeed I haven't used numpy or cv yet and will have to start with learning how to install them. Up to now I have just used Python with text i/o to try and get my head around all these higher level data representation abstractions and the associated nomenclature. I am a very low level programmer.
In principle thats correct, its just an array or in python terms a nested list where a list contains other lists that contain ... as so on.
When the image is loaded, say into a variable called img, info on the image is obtained by doing
For example if I do this on my small image containing the image I want to try to find in the main image I get height=74, width=100, depth=3 showing that the image is 74 rows x 100 columns with 3 channels representing the Blue, Green, Red colours.
I can also just print the list data by just doing a print(img) which would show data in the following format.
[[[26 37 53]
[40 52 69]
[43 56 74]
...
[62 75 95]
[61 72 88]
[36 43 56]]
[[25 36 52]
[41 54 71]
[42 55 73]
etc.
I've mainly been using OpenCV on my mac, but I have also installed on a raspberry pi. For testing purposed its best to create a python virtual environment and install the opencv into this. From memory I think it was just a case of activating the virtual environment and doing a pip3 install opencv but I did not make any notes and the installation instructions are readily available with a google.
Here is a handy link to some OpenCV on python docs
Mustered up some motivation to work on coding my robot base. It is somewhat hard to share because all visual processing code is written in FreeBASIC and a Python version would be much too slow.
Good to see you are getting back in to a robot project again. 😀 Depending on what you mean by visual processing, then python may not be too slow as the openCV libraries are all written in C as is the numpy library.
The encoder ticks program could be written in python, but I think a good option may also be to count the encoder ticks with a microprocessor running C and just to pass more summarised data to the visual display. And indeed I think thats what you are saying.
Maybe the start point could be using openCV in python to determine the position and direction the robot is facing, then to issue commands to the microprocessor to so something like rotate 90 degrees and the proceed for 100 cm etc. The microprocessor then keeps the robot robot on the straight and narrow by means of checking the encoder feedback.
What I would like to get around to doing on a connected laptop is a graphics display of the 2d position of the robot as it moves around. To share I would have to write a Python version.
However I think you are saying you want to represent the robot on the screen as a visual 'blob' (were the front of the robot is indicated) and then, as the robot moves, you want to display its movements as a trace on the screen.? (and from its second position, I'm not quite with that yet). But any help I can be in producing any python programs you need I will chip in as time allows.
Last month I installed opencv for Python. This works for me gets and displays video from the webcam,
import cv2 as cv
capture = cv.VideoCapture(0)
while True:
isTrue, frame = capture.read()
cv.imshow('Video',frame)
if cv.waitKey(20) & 0xFF==ord('d'):
break
capture.release()
cv.destroyAllWindows()
I am using Python39, I ran your above Python program with three images
# the file names of the images:
myImage = 'C:/cvImages/image.jpeg'
myBot = 'C:/cvImages/tabasco.jpeg'
myTarget = 'C:/cvImages/tape.jpeg'
but got errors,
Traceback (most recent call last):
File "C:\Users\casey\AppData\Local\Programs\Python\Python39\bryonCV1.py", line 23, in <module>
cv2.imshow('Untidy Office', cv2.imread(myImage))
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1i5nllza\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
A quick post on your AttributeError: module 'serial' has no attribute 'Serial' problem.
I use a mac so I ran the following code, putting the serial port of an unsupecting wemos Esp8266 board
I am using Python39, I ran your above Python program with three images
I copied your images and put them in my images directory. This images directory sits under the directory where the python code is located.
And it all works as expected, the robot_builder image pops up, focus on the image and keep pressing a key to see the sequence unfold, ending in the bearing calc as shown below.
So it must be something to do with the way the image paths are resolved, so I think it will all work if you create the image directory as mentioned above.
and dont forget the bearing calc shown on the output terminal will need adjusting as per
Thanks for the feedback. Will have to work on
... my main target is outdoor bots ...
For me I have no use for an outdoor bot but even then I would be more interested in visual location and navigation than using GPS just for the challenge. You wanted to chase rabbits and foxes away from the veg patch? I would use a quadrocopter which have the GPS and a camera.
Quadrocopter Ball Juggling
You wanted to chase rabbits and foxes away from the veg patch? I would use a quadrocopter which have the GPS and a camera.
I've morphed the robotic intentions, initially at least, to making it go on periodic rabbit / surveillance patrols, maybe sending a squirt of water in the general direction of rabbit activity. It will also serve as a mobile camera mount so I can see whats up (doc) around the premises and it will be summoned when the drive gate is opened to see who is visiting. I want to build one that can run for extended periods, probably using car batteries, sort of a mini golf buggy.
Those little quadcopter are only good for about 20 minutes, and the bigger ones too expensive. But a little quadcopter drone would be a fun addition to compliment foxbot so maybe.. 😎
You wanted to chase rabbits and foxes away from the veg patch? I would use a quadrocopter which have the GPS and a camera.
I've morphed the robotic intentions, initially at least, to making it go on periodic rabbit / surveillance patrols, maybe sending a squirt of water in the general direction of rabbit activity. It will also serve as a mobile camera mount so I can see whats up (doc) around the premises and it will be summoned when the drive gate is opened to see who is visiting. I want to build one that can run for extended periods, probably using car batteries, sort of a mini golf buggy.
Those little quadcopter are only good for about 20 minutes, and the bigger ones too expensive. But a little quadcopter drone would be a fun addition to compliment foxbot so maybe.. 😎
So, why not have the quadcopter sit on the top of the robot and be charged by it and launched by it. Then you can have the bot cruise the grounds casually and launch the quad to check out visitors as well as scare off rabbits, buskers and estate agents as required 🙂
Anything seems possible when you don't know what you're talking about.
So, why not have the quadcopter sit on the top of the robot and be charged by it and launched by it.
Very ambitious thoughts there! (and maybe a whole squad of such bots to serve as the ultimate defence of my realm)
Absolutely, have you seen the drones that fly up to a wall and hang themselves vertically ? You could have up to 5 drones (one on each side and one on the "roof") and customize each one for a different kind of varmint 🙂
Anything seems possible when you don't know what you're talking about.
The idea is to have the drone on standby. Using a camera to detect movement (and size of moving object) then the drone can be activated to dive bomb the rabbits or fox for 15 minutes like a buzzing swarm of bees. It could get to the drive gate to send back video so you can see who is visiting. They are great little devices and can navigate themselves back to home base before the battery runs out. One day I suspect with future warfare thousands of them will appear on the horizon to take us out, something to think about in terms of drone defence.
It was the drone keyword in a google search that I first came across Bill's dronebot workshop.