#๐ Overflowing error, negative numbers wrap around.
39 messages ยท Page 1 of 1 (latest)
@nova dust
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hello, please remember to always share code and text as actual text. Not as a screenshot
!code
Whatever you're working with, you probably need to change the data type from an 8 bit integer to something larger.
if layer_frame_count % 4 == 0 and layer_frame_count > 20:
first_five_entries = list(samplewise_max.values())[:5]
last_four = [entry[-4:] for entry in first_five_entries]
result = [sublist[3] - sublist[0] for sublist in last_four]
result2=[x/4 for x in result]
der_test= sum(result2)/len(result2)
if der_test > 10:
print('increasing')
plt.imshow(frame,cmap='gray')
plt.show()
elif der_test < -10:
print('decreasing')
plt.imshow(frame,cmap='gray')
plt.show()
``` Sorry I figured the screenshot would be more helpful since it shows the overflowing occuring
the py needs to be on the same line as the ```
can you show the code that creates samplewise_max?
or just put the whole thing in the paste bin
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
Here is the whole script. It is for image processing of an IR video.
The pixel intensities in question range from 0-255, hence the overflow of negative numbers to 255-# I believe
try changing converted_list to an array with a float dtype
converted_list = np.array([struct.unpack('b', struct.pack('B', x))[0] for x in sfp2], dtype=np.float32)
you'll need to change the code that comes after it to account for it being an array, and not a list.
that should allow the values to go above 2 ** 8 and below 0
if layer_frame_count % 4 == 0 and layer_frame_count > 20:
first_five_entries = list(samplewise_max.values())[:5]
last_four = [entry[-4:] for entry in first_five_entries]
result = [sublist[3] - sublist[0] for sublist in last_four]
result2=[x/4 for x in result]
der_test= sum(result2)/len(result2)
if der_test > 10:
print('increasing')
plt.imshow(frame,cmap='gray')
plt.show()
elif der_test < -10:
print('decreasing')
plt.imshow(frame,cmap='gray')
plt.show()```
The if statement in question doesn't draw from converted_list. Converted_list was to account for the overflow being generated previously, sending the numbers back to negative if it occured.
Infact I am probably going to delete the whole if statement that converted_list came from
okay. python ints and floats don't overflow like this, so the problem must be coming from some other array-like object (that contains non-python numbers)
could it be one of these?
ret, frame=video_capture.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
Probably. That's where the values of the intensity are drawn from
The sample_mins, sample_maxs, and sample_sums just do what the name implies for each frame. There are 10 samples in each frame, and those lists store the values for each sample then append them to the main dict's
for what you're doing, if a number goes over 256 or under 0, does that not mean that you made a mistake mathematically?
Well, no I am trying to take the derivative of the values. Let me explain. Its a lengthy explanation and I am not the best at technical writing so bear with me:
no need. I just wanted to check.
ok
I haven't worked with cv2. is frame an array? can you do cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY).astype(float)?
Yes. Let me check
then what I said should convert it from uint8 to float64, or something like that.
Yep. that worked.
Wow that was simple
Thanks for your help
this is the only kind of situation where you actually need to know about unsigned ints and shit
I mean I guess there are others
but I feel like the whole "computer architecture" course could be boiled down to three lectures of relevant content
Yeah. Unfortunately my mech engineering education didn't teach me about that stuff. Wish they would have.
point is, unsigned 8 bit integers let you represent 2^8 values with only 8 bits. so if you want to only represent RGB values, it's more space efficient to use 8 bits instead of 16, or 32, etc.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.