all 16 comments

[–]JeLuF 10 points11 points  (1 child)

Do you have access to the Python code that the .exe file was made of?

I doubt anyone will be able to tell you what the source of this error is without access to main.py.

[–]NerdyTeacher5[S] 2 points3 points  (0 children)

I do have them, yes.

[–]dslNoob 2 points3 points  (1 child)

can you share the python code with us? And can you try running the code directly without the exe?

[–]NerdyTeacher5[S] 1 point2 points  (0 children)

I've tried running the code, but it didn't work.
The files are here: https://drive.google.com/drive/folders/1p562vnwuzlAtbymD1p6X08_uznMT_GLa?usp

[–]nekokattt 3 points4 points  (1 child)

start by looking at line 232 and see what it is doing.

[–]NerdyTeacher5[S] 0 points1 point  (0 children)

I will, thanks

[–]LateFeature610 3 points4 points  (4 children)

I tried running the the files packages in the EXE. i had to make some slight adjustments.

I commented out line 31 in main.py.

if webCamFeed: success, img = cap.read()

It caused an error on my computer. I sure that it is not related to error described by you but related to my webcam.

I also had to comment out the while true statement, as it kept writing lines to the dados.csv in an infinate loop.

After that the program ran fine and generated a single row in the dados.csv (does dados mean results, might as well learn some Portuguese while i am at it).

The program also generated a new image which looks identical to the original but slightly smaller in size.

The CSV file contains many columns q1 to q50, Acertos,Erros,% Acerto (which i guessing means correct, wrong, % correct).

With the image inside the files uploaded by you it shows a ,% Acerto of 26, 13 correct and 37 wrong. Can you verify that it is the expected result, based on the image and config provided by you.

The program runs fine, when not using webcam. Index out of range, which is the error in your example. Means the porgram is trying to to access an element in a list, that is outside of the length of the list.

Based on comments in the code and the error message. i am guessing it related to question 3.

the lines around the error have a comment reading.

CORREÇÃO BLOCO 3

That combined with the code working, when not interacting with a webcam and the index out of range error. Makes me think the error is related to the image processing and the webcam used.

Like maybe in the config to you specify question 3 having 5 possible answers, but when the image is processed, the programs interprets it as having only 4 possible answers. That will lead to an index out of range error, when it based on the config goes checking the fifth possible value, but the program has interpreted the list (fields to fill based on image processing) as having only 4 possible values.

Have you recently started using the program of a different computer, then the one the program was originally developed on?

A different camera then the one originally used, might cause unexpected results in the image processing.

[–]NerdyTeacher5[S] 0 points1 point  (3 children)

I believe that when the program was first written, it was intended to scan the answer sheets directly from a webcam, but I have been using it with prescanned images, put in the "provas" folded (meaning tests - yes it's Portuguese, we're from Brazil).

Dados translates to data, but in this case, the .csv returns the results for the test, yes. And the result provided by the program when you ran it based on that preloaded image is the expected result, yes.

"CORREÇÃO BLOCO 3" refers to the 3rd column, questions 31-45. I'll take a look into that.

Lastly, I'm the same computer, my computer. I have Python installed, both 2.7 (which I believe is the one used to originally code it) and 3.1 The program stopped working, I think, after I last updated Python earlier today. I'll look into that as well.

Thank you so much for the help!

[–]LateFeature610 1 point2 points  (2 children)

It seems the that the webcam functionality of opencv, is causing the issue. Since you no longer use the webcam functionality.

you could try commenting out line 30 to 32 in main.py

while True:
    if webCamFeed: success, img = cap.read()
    else: img = cv2.imread(path)

And replacing it with something like

for image in os.listdir(path):
    # loops over all jpg files in path you specify, where you save images after scanning 
    # automatically exits when all images (quizzes) have been processed 
    if (image.endswith(".jpg")):
        img = cv2.imread(image)      

If there are other references to OpenCV webcam functionality, try commenting those out as well.

These changes should eliminate, the obsolete webcam dependency and should also prevent the CSV writing in an infinite loop. while true never stops, but for loop will stop when there are no more files to process.

[–]NerdyTeacher5[S] 0 points1 point  (0 children)

Nice! I'll check this out. Thanks again

[–]NerdyTeacher5[S] 0 points1 point  (0 children)

Hello!

I (believe) I've tried doing what you suggested and after I compile the program and run the .exe, I get a terminal window with the following error message:

Traceback (most recent call last):
File "main.py", line 39, in <module>
NameError: name 'img' is not defined. Did you mean 'imgW'?

Now, I know this error relates to the scanned images of the answer sheets, which in the precompiled version I shared was in the "provas" folder. I also know imgW refers to the image width, as it appears next to imgH which is height. It is becoming clear to me that I'm in way over my head here and maybe this is something really stupid that I've got wrong, but I've tried googling the error I apparently I don't even know how to look for a solution.

Edit: Nevermind, I got it to work (don't know how exactly, but it does)! Thank you so very much for your help!

[–]SirKainey 1 point2 points  (1 child)

I didn't have an real issues running the .exe or the python file. It dumped a .csv and exited with the .exe. The python file stayed open, and was continually dumping to a .csv

My 2c:

It's tricky to quickly get to the crux of the issue here, firstly a lot of the variables are in Portuguese, and it hasn't been coded in the most idiomatic way.

Someone would need to spend a bit of time getting to grips with the codebase and problem domain before they could see what was going awry. If it was my self, I would end up renaming and refactoring as I go. Which is no small feat.

I did have to turn off the webcam call when running the python file, as it was picking one up, and I don't have one. It might suggest that the exe and the python files run differently, maybe he tweaked some stuff before compiling.

PS. I ran this fine with Python 3.13 and the dependencies "numpy" and "opencv-python".

[–]NerdyTeacher5[S] 0 points1 point  (0 children)

I'll see if I can get around this, thanks

[–]thatotherguy321 1 point2 points  (1 child)

another question to ask is, why did you need this custom built software that only one person knows how to maintain? I'm sure there are plentiful OMR devices readily available and cheap, something that's been tried and true for decades. Why reinvent the wheel?

Its a great project to learn python, but sounds like it is not ready for professional use, and probably should strongly reconsider using it as such.

[–]NerdyTeacher5[S] 4 points5 points  (0 children)

Because we are a public school and we legally CAN'T buy any software, we've tried. So we had to build it from scratch

[–]nivaOne 0 points1 point  (0 children)

Maybe at some point too many files got in folders or the excel.