I am new to using OpenMV but I am having a few difficulties. I hope you guys can help give me some advice. I am struggling to transfer my python code in analysing the image to the device. At the moment I am stuck with extracting the pixel value in the image. I tried different approaches but keep getting error messages. Here is part of the code in python that I want to implement on the device:
for i in range(0, image_size[1]):
for j in range(0, image_size[0]):
analysed_array[i,0] = analysed_array[i,0] + pix[j,i]
In this example code I am reading in the image taken from the camera on my computer. I want to convert the i by j array of the cropped image to a i by 1 array by summing along the x-axis (horizontal). This section of the code works well on python and I get the result I want but when I transfer this to OpenMV device I get errors for using “zeros” and “image.load()”. I am stuck and not sure how to proceed. What I want to achieve is finding the pixel value of each i and j position.
Hope you guys can help and guide on how to achieve my goal.
Thanks for your reply. I am sad to hear I cannot do a pixel level analysis. The main thing is I want to identify how the grayscale value of a dark line in a section of the image changes over time. I was hoping I could use the camera to take the image and measure this value. It would be much quicker than trying to upload the image elsewhere or transfer to a desktop to carryout this analysis.
Is there no other way of finding the grayscale or rgb values of the image array? I dont need to do any manipulation but knowing the value at least would be useful.
Just iterate through the image and keep track of the minimum pixel value you see. If you keep the region of interest small the code will run decently fast.
I am happy with the slow processing time for my application. Its only a small section of the image between 5 to 10 pixels. But I am struggling to get the last part of the code working. Here is an example of what I like to achieve is below:
for i in range(0, 5):
pixel_value[i,0] = img1.get_pixel(0, i)
chosen_value = pixel_value[1,0]
But I cant carry out the above code as I get an error. I am sorry I am being quite annoying here but if I can at least get same pixel value in an array and read it out later, I do the rest using the example code I found on the IDE.
Apologises. I should have included the error in the last message. The first error I get is for this line of code:
pixel_value[i,0] = img1.get_pixel(0, i)
Nameerror: name pixel_value is not defined
If I use the following code, I don’t get an error.
pixel_value = img1.get_pixel(0, i)
so it seems to be an issue when I try to use index for the array. How could I store some of the pixel values in an array? Also how could I read the values out of the array? Like:
I think Nyamekye already answered this you cant index like that, python doesn’t know what structure your trying to use. If you want to use a list you need to define it as
mylist = []
for example before you use it. Then you can Insert a value into a certain index position of the list using the following notation:
mylist[index] = value
If you want to get a value from the array just use:
value = mylist[index]
If you are trying to store the pixels values in an array use the following:
pixel_values = []
for i in range(0,5):
pixel_values.append(img1.get_pixel(0, i))
This example could be made much more elaborate but thats the most basic way of showing you.
Thank you so much for all your help. I have been struggling with the array. I couldn’t figure out how to add to the array. I greatly appreciate all your help and for your patience with me. Sorry for being so annoying.