Sift Implementation in Vlfeat - sift

I am using the Sift implementation by Vlfeat.org. It has the follwing function which is supposed to save the features to a file.
def process_image(imagename,resultname,params="--edge-thresh 10 --peak-thresh 5"):
""" process an image and save the results in a file"""
if imagename[-3:] != 'pgm':
#create a pgm file
im = Image.open(imagename).convert('L')
im.save('tmp.pgm')
imagename = 'tmp.pgm'
cmmd = str("sift "+imagename+" --output="+resultname+
" "+params)
os.system(cmmd)
print 'processed', imagename, 'to', resultname
Here how the line "os.system(cmmd)" is supposed to write the results in a file?
I am on an ubuntu machine and if I execute "sift" as command in terminal, I am getting the result as "not found". On linux, which process is this command trying to invoke? I need to save these Sift features into a file so that later I can use it to create Bag of Words descriptor for clustering.
A similar sift implementation at https://github.com/jesolem/PCV/blob/master/PCV/localdescriptors/sift.py also uses the same line to save the result into file.

On linux, which process is this command trying to invoke?
This refers to the command-line tool provided by vlfeat (see vlfeat/src/sift.c):
$ ./sift
Usage: ./sift [options] files ...
Options include:
--verbose -v Be verbose
--help -h Print this help message
--output -o Specify output file
...
You can either use the binary distribution from vlfeat download page (see bin/glnxa64/sift for Linux 64-bit), or directly clone the repo and compile it from sources.
Make sure to adjust the path with cmmd = str("/path/to/sift " ...) or install (= copy it) under a common path like /usr/local/bin.

Related

Write a File from Jenkins Groovy Script-Console

I'm trying to find a way to write some content to a file using Jenkins Groovy Script-Console.
The use-case: Our CI manages some state-machine using a volume shared between all the nodes (which is in turn mapped to EFS). However - following the discovery of a bug in our CI groovy shared libs I found that some state files gone corrupt, and needed to write to them the corrected values, together with fixing the bug.
I could do that using ssh connection, however, as we're in process of abstracting out the workers we're trying to back off from that and manage ourselves only from the script-console and/or ci jobs.
I tried all these forms, all of which failed:
"echo 'the text' > /mnt/efs-ci-state/path/to/the-state-file.txt".execute().text
"""
cat <<<EOF > /mnt/efs-ci-state/path/to/the-state-file.txt
the text
EOF
""".execute().text
"bash -c 'echo the text > /mnt/efs-ci-state/path/to/the-state-file.txt'".execute().text
"echo 'the text' | tee /mnt/efs-ci-state/path/to/the-state-file.txt"
Can anybody show me the way to do that?
I'd also appreciate an explanation why the forms above won't work and/or a hint on how to execute commands that include piping and/or stdio directing from that script console.
Thanks :)
["bash", "echo the text > /mnt/efs-ci-state/path/to/the-state-file.txt"].execute().text
or use plain groovy:
new File('/mnt/efs-ci-state/path/to/the-state-file.txt').text = "echo the text"
why not working:
options 1, 2, 4 : echo and piping is a feature of shell/bash - it will not work without bash
option 3 you have c echo and c is not a valid command
use array to execute complex commands and to separate bash from main part
i suggest you to use this kind of code if you want to capture and validate stderr
["bash", 'echo my text > /222/12345.txt'].execute().with{proc->
def out=new StringBuilder(), err=new StringBuilder()
proc.waitForProcessOutput(out, err)
assert !err.toString().trim()
return out.toString()
}

Remove Thumbnail from MP3 FILE - from yt-audio

When using yt-audio, how can you remove the thumbnail image (artwork / screenshot) that comes with the downloaded mp3 file?
Best would be to have a way of doing it by adding an additional argument to the command, but looping through the downloaded files works too if someone knows how to do that.
Just in case, this is the description of the yt-audio usage:
usage: yt-audio [OPTIONS] REQUIRED_ARGS
A simple, configurable youtube-dl wrapper for downloading and managing youtube audio.
Required Arguments (Any/all):
URL[::DIR] Video/Playlist URL with (optional) save directory [URL::dir]
-e, --example1 Example playlist [Custom]
--all All [Custom] Arguments
Optional Arguments:
-h, --help show this help message and exit
-v, --version show version and exit
--use-archive use archive file to track downloaded titles
--use-metadata use metadata to track downloaded titles
--output-format [OUTPUT_FORMAT]
File output format
--ytdl-args [YTDL_ADDITIONAL_ARGS]
youtube-dl additional arguments
Thank you all!!
So in the end, I found the answer to this one myself (quite ashamed of the time it took me though.)
To remove the thumbnail, don't download it.
That sums it up basically.
To not download the thumbnail, I simply needed to edit the common.py file once yt-audio was installed.
The file is in the installation, under: yt_audio/common.py
Editing the common.py file.
In common.py find the Common class, and edit DEFAULT_ARGUMENT_VALUES.
Or simply replace the value assigned to it, with this thumbnail-less version (below).
DEFAULT_ARGUMENT_VALUES = {
'download_command': 'youtube-dl -x -q --print-json --audio-format mp3 --audio-quality 0 '
'--add-metadata -o "$OUTPUT$" $URL$',
'playlist_info_command': 'youtube-dl --flat-playlist -J $PLAYLIST_URL$',
'output_format': '%%(title)s.%%(ext)s',
'ffprobe_command': 'ffprobe -v quiet -print_format json -show_format -hide_banner "$PATH$"',
'output_directory': str(PurePath(Path.home(), "Music"))
}
That's it.

Redirect lldb output to file

I'm using lldb inside Xcode, and one of my variables contains a huge chunk of JSON data. Using po myVar isn't much helpful to analyse this data, as it will output in the tiny Xcode debug console.
Is there a way to redirect lldb output to a file ?
I saw here that such a feature seems to be available on gdb as :
(gdb) set logging on
(gdb) set logging file /tmp/mem.txt
(gdb) x/512bx 0xbffff3c0
(gdb) set logging off
and is "translated" in lldb as :
(lldb) memory read --outfile /tmp/mem.txt --count 512 0xbffff3c0
(lldb) me r -o/tmp/mem.txt -c512 0xbffff3c0
(lldb) x/512bx -o/tmp/mem.txt 0xbffff3c0
However, the memory read command will not help in my case, and apparently, --outfile is not available for the print command.
You can use a Python script to do so (and much more), as explained here:
LLDB Python scripting in Xcode
Create a file named po.py in a directory of your choice (for example "~/.lldb"):
import lldb
def print_to_file(debugger, command, result, dict):
#Change the output file to a path/name of your choice
f=open("/Users/user/temp.txt","w")
debugger.SetOutputFileHandle(f,True);
#Change command to the command you want the output of
command = "po self"
debugger.HandleCommand(command)
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f po.print_to_file print_to_file ')
Then in lldb write:
command script import ~/.lldb/po.py
print_to_file
I found session save <filename> to be a much better, easier option than those listed here. It's not quite the same as you can't use it (to my knowledge selectively) but for generating logs, it's quite handy.
Here is a slight modification incorporating some of the comments from above:
def toFile(debugger, command, result, dict):
f=open("/Users/user/temp.txt","w")
debugger.SetOutputFileHandle(f,True);
debugger.HandleCommand(command)
f.close()
debugger.SetOutputFileHandle(sys.stdout, True)
This allows the command to be supplied as an argument, and reverts the output file handle to stdout after the command is run.
Assuming that you have a variable named jsonData (which has a Data type) you can save it to a file with this command:
expr jsonData.write(to: URL(fileURLWithPath: "/tmp/datadump.bin"))
Alternatively instead of above command you could dump memory used by this variable to a file as in the example below:
(lldb) po jsonData
▿ Optional<Data>
▿ some : 32547 bytes
- count : 32547
▿ pointer : 0x00007fe8b69bb410
- pointerValue : 140637472797712
(lldb) memory read --force --binary --outfile /tmp/datadump.bin --count 32547 0x00007fe8b69bb410
32547 bytes written to '/tmp/datadump.bin'

How to query Maya in script for supported file translator plugins?

I'm trying to specify an FBX file in MEL using the command
file -f -pmt 0 -options "v=0;" -typ "FBX" -o
on one computer this works great. On another, it fails but DOES work if I use
-typ "Fbx"
I think I'd like to query for the supported translators in my script, then either select the correct one or report an error. Is this possible? Am I mis-diagnosing the problem?
MEL has a command called pluginInfo. You could write a simple function that will return the proper spelling based on that. pluginInfo -v -query "fbxmaya"; will provide the version of the fbx plugin. I haven't used MEL in a while so I'm not gonna try to make this perfect but maybe something like if(pluginInfo -v -query "fbxmaya") ) string fbxType = "FBX" else( string fbxType = "Fbx"). Then just plug that var into file -f -pmt 0 -options "v=0;" -typ $fbxType -o.
It might be a different version of fbx. You'd have to provide another line which determines the version of fbx on that particular machine and pipes in the correct spelling.

Change File Encoding to utf-8 via vim in a script

I just got knocked down after our server has been updated from Debian 4 to 5.
We switched to UTF-8 environment and now we have problems getting the text printed correctly on the browser, because all files are in non-utf8 encodings like iso-8859-1, ascii, etc.
I tried many different scripts.
The first one I tried is "iconv". That one doesn't work, it changes the content, but the file's encoding is still non-utf8.
Same problem with enca, encamv, convmv and some other tools I installed via apt-get.
Then I found a python code, which uses chardet Universal Detector module, to detect encoding of a file (which works fine), but using the unicode class or the codec class to save it as utf-8 doesn't work, without any errors.
The only way I found to get the file and its content converted to UTF-8, is vi.
These are the steps I do for one file:
vi filename.php
:set bomb
:set fileencoding=utf-8
:wq
That's it. That one works perfect. But how can I get this running via a script?
I would like to write a script (Linux shell) which traverses a directory taking all php files, then converting them using vi with the commands above.
As I need to start the vi app, I do not know how to do something like this:
"vi --run-command=':set bomb, :set fileencoding=utf-8' filename.php"
Hope someone can help me.
This is the simplest way I know of to do this easily from the command line:
vim +"argdo se bomb | se fileencoding=utf-8 | w" $(find . -type f -name *.php)
Or better yet if the number of files is expected to be pretty large:
find . -type f -name *.php | xargs vim +"argdo se bomb | se fileencoding=utf-8 | w"
You could put your commands in a file, let's call it script.vim:
set bomb
set fileencoding=utf-8
wq
Then you invoke Vim with the -S (source) option to execute the script on the file you wish to fix. To do this on a bunch of files you could do
find . -type f -name "*.php" -exec vim -S script.vim {} \;
You could also put the Vim commands on the command line using the + option, but I think it may be more readable like this.
Note: I have not tested this.
You may actually want set nobomb (BOM = byte order mark), especially in the [not windows] world.
e.g., I had a script that didn't work as there was a byte order mark at the start. It isn't usually displayed in editors (even with set list in vi), or on the console, so its difficult to spot.
The file looked like this
#!/usr/bin/perl
...
But trying to run it, I get
./filename
./filename: line 1: #!/usr/bin/perl: No such file or directory
Not displayed, but at the start of the file, is the 3 byte BOM. So, as far as linux is concerned, the file doesn't start with #!
The solution is
vi filename
:set nobomb
:set fileencoding=utf-8
:wq
This removes the BOM at the start of the file, making it correct utf8.
NB Windows uses the BOM to identify a text file as being utf8, rather than ANSI. Linux (and the official spec) doesn't.
The accepted answer will keep the last file open in Vim. This problem can be easily resolved using the -c option of Vim,
vim +"argdo set bomb | set fileencoding=utf-8 | w" -c ":q" file1.txt file2.txt
If you need only process one file, the following will also work,
vim -c ':set bomb' -c ':set fileencoding=utf-8' -c ':wq' file1.txt

Resources