0

I am trying to run create a codebook from a database of images using colordescriptor.exe. The code comes with an python scirpt which is actually a scirpt to create a codebook. In the usage example it says thath I have to run the following command to console: python exampleCreateCodebook.py trainimages.txt outputFilename, where trainimages.txt a list of dataset images and outputFilename the name of the output codebook. When I tried to run the command (from the dir that the .exe is located) I got the following error:

Traceback (most recent call last):
File "exampleCreateCodebook.py", line 112, in <module>
sys.exit(main())
File "exampleCreateCodebook.py", line 109, in main
return process(options, args)
File "exampleCreateCodebook.py", line 80, in process
raise Exception("Error when executing '%s': command returned error" % cmdLine)
Exception: Error when executing 'colorDescriptor.exe C:\sift\fashion1\00010big.jpg --keepLimited 30 --outputFormat binary --output c:\users\user\appdata\local\temp\tmp9qzldd --detector densesampling --ds_spacing 6 --ds_scales 1.2 --descriptor opponentsift': command returned error

How can I run properly the exampleCreateCodebook? Is there a chance I am gettting problems due to os.system function? The scirpt file is the following. I have noticed that my program fails in line 80 since returnCode is equal to -1. Thus it seems that os.system(cmdLine) doens't run properly. I tried to change the above command with returnCode =subprocess.call(['cmd', '/k', cmdLine] ). When I did so the scirpt was iterate just one time inside the for loop and it stops after the subprocess.call. Is subprocess responsible for stoping the for-loop?

for inputImage in inputImages:
    cmdLine = "%s %s --keepLimited %d --outputFormat binary --output %s %s" % (binarySoftware, inputImage, keepLimited, tempFilename, extractionConfig)
    print cmdLine
    subprocess.call(['cmd', '/k', cmdLine] )
    print 'ole'

List inputImages contains 1000 images. However the for loop stops after first iteration, at the first call of subprocess.

2
  • What if you execute the command directly from command line, without involving Python at all? Commented Feb 5, 2015 at 13:00
  • For loop is just part of the code, which creates a dictionary from local features which are calculated for every image inside for loop. When I try to execute the command from console it runs properly. However, I am trying to find a solution in order to use exampleCreateCodebook script. Commented Feb 5, 2015 at 13:02

1 Answer 1

2

Is the output that you've shown correct? It doesn't look like it's been copied verbatim.

Looking at the example Python code, it is not possible for the exception to be raised at line 80 and for line 82 to be executed.

If by some miracle it is executing line 82, the IOError: [Errno 22] Invalid argument would be happening if the output file generated by colorDescriptor.exe is less than 4 bytes long. This would likely be the case when the colorDescriptor.exe fails as it has during your run. Lines 84-85 of DescriptorIO.py:

identify = f.read(4)
f.seek(-4, os.SEEK_CUR)

Looks like a bug where it is assumed that the file will have at least 4 bytes. If it doesn't seek() will fail with IOError.

You need to work out why colorDescriptor.exe is failing. Try running the program manually and you might discover the source of the problem:

colorDescriptor.exe C:\sift\fashion1\00010big.jpg --keepLimited 30 --outputFormat binary --output    c:\users\user\appdata\local\temp\tmpywsquy --detector densesampling --ds_spacing 6 --ds_scales 1.2 --descriptor opponentsift

N.B. I altered the above command removing the spaces in -- keepLimited because that's what the code should generate. If it really is generating spaces in the command, that might be the problem.

Sign up to request clarification or add additional context in comments.

7 Comments

When I run the program from terminal it worked fine. When I change the os.system to sybprocess.call, it executes just one time the .exe, it created one temporal local features and it stops. However when i tried the code as it is reurnCode was equal to 1. I thnk that I got an error on the output code.
In the terminal, did you run the exact command in the same directory? Does the file C:\sift\fashion1\00010big.jpg exist and can it be opened by the exe? I don't think that this is a problem with os.system(). It's probably something to do with the exe, the generated command, or the image files (location and/or permissions).
@JoseRamon: the traceback makes more sense now.
I have noticed that when I try to run a simple example of code with subprocess.call: for file in onlyfiles: subprocess.call(['cmd', '/k', pattern] ) //pattern an echo. I manage to run it only one from terminal. When I call python file from terminal. However with sublime it runs it properly(len(onlyfiles) times).
@Timo: probably you would be better off using subprocess.run() to execute your command with arguments.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.