@byron FYI @tfmccarthy
So can I use Python in my project visual control of a robot?
In my other thread I wanted to blob high contrast signs and then use the result to identify the sign and its descriptions. To be useful you need not only process and image you need to be able to extract data that enables you to "recognize" things like a STOP sign and so on ...
import cv2 import numpy as np # Load the color image image_path = 'D:/target8.png' # Change this to your image path color_image = cv2.imread(image_path) # Check if the image was loaded correctly if color_image is None: print("Error: Could not load the image.") exit() # Convert the color image to grayscale gray_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY) # Optionally, apply a Gaussian blur to reduce noise blurred_image = cv2.GaussianBlur(gray_image, (5, 5), 0) # Apply a binary threshold to get a binary image _, binary_image = cv2.threshold(blurred_image, 128, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU) # Optional: Use morphological operations to enhance binary blobs kernel = np.ones((5, 5), np.uint8) # Define a kernel size binary_image = cv2.morphologyEx(binary_image, cv2.MORPH_CLOSE, kernel) # Save or display the binary blobs cv2.imwrite('D:/bb3.png', binary_image) # Save the binary image cv2.imshow('Binary Blobs', binary_image) # Display the binary blobs cv2.waitKey(0) cv2.destroyAllWindows()
So can I use Python in my project visual control of a robot?
You can. I refer you to the post of a few years ago which you recently gave a link to for @tfmccarthy to have a peruse of. Its been a while since I had a play with OpenCV but a quick peruse of the example code I presented shows I looped though 6 different algorithms that OpenCV had (at that time) to recognise a target image within a main image to be scrutinised for a match. I then calculate an x,y coordinate representing the centre of where the image was to found in the main image.
I then selected one of the algorithms and used it to find the location of each of two target images within a main image (botResult and targetResult). The supposition in this example was that the camera position was looking from above down upon a 'bot' and a 'target' position and, supposing the top of the image was north etc., a compass bearing was calculated from the bot coordinates to the target coordinates.
So taking that sort of approach, amended to assume the camera was on the bot and it finds the target coordinates in terms of the image frame, you can calculate the distance the target is adrift from the centre of the image frame (in terms of left or right and ignoring the vertical aspect) to apply an appropriate command to make the bot wheels turn to align the target to the centre of the image.
But whilst python is commonly used for computer vision applications with a wide number of modules like openCV and numpy and a lot of machine learning stuff, all the base programming done in C or C++ and no doubt other low level stuff. You may be more interested in using the likes of those target recognition algorithms from C++ rather then python. For example, one of the algorithms I used in the code I mentioned above was cv.tm_ccoeff_normed and the C++ code can be found in the OpenCV docs, and I give a link below:
https://docs.opencv.org/3.4/de/da9/tutorial_template_matching.html
You may be better off using and amending the C++ code for your requirements rather than using python. I know which route I would prefer, but I think yours may differ.
Searching the internet I have been finding a lot of examples on using Python for vision. I have just found one relevant to my FreeBASIC code that converts an image of blobs into blob descriptions including parent child relationships of blobs within blobs.
https://github.com/petercorke/machinevision-toolbox-python
And this pdf covers a lot of vision stuff with Python code.
http://programmingcomputervision.com/downloads/ProgrammingComputerVision_CCdraft.pdf
Python seems to have taken over as the high language of choice while C++ for the more advanced programmer who can write all the underlying stuff used by Python?
Python seems to have taken over as the high language of choice while C++ for the more advanced programmer who can write all the underlying stuff used by Python?
It's not a contest of "which is better" or "most popular." C++ is a hybrid language and can function at both extremely abstract and extremely low levels. It's a complex language but can be used in simple ways. Its main attribute is efficiency. Python is a language that simplifies the programming complexity by providing a "safe" environment in which to operate. The language is complex (but not too complex) and the environment is rich in feature support. But this comes at a cost: you have to have the environment support. If the platform doesn't support the environment (or a restricted one, e.g., micropython) then you're blocked. However, Python has lots of platform support. And only on very restricted platforms or applications, where efficiency rules the day (e.g., games), will the distinction be a deciding factor.
That said, the current trend is that programmers are more attracted to Python due to the complexity question; they find it easier to understand the language. And the C++ community has really lagged behind in terms of providing good coding examples. But the technical arguments are no longer that persuasive to today's programmers.
But don't use the artificial measure of popularity to select the language. In its day, BASIC was universal. PL/1 and Pascal were the answer to the "software crisis." C is still very popular and its over 50 years old! Every dog has its day.
The one who has the most fun, wins!