I would like to show an image in opencv. I create a window using "namedWindow" and show the image using "imshow". at the end of the code I use "cin" so the program does not quit automatically. part of my code looks like this:
namedWindow("image");
imshow("image",aa);
waitKey(500);
cin >> aaa;
return 0;
If I eliminate the waitKey statement, I cannot see the image. Why is it like that ? the next statement (cin >> aaa) is not executed after imshow is done ? why is a delay essential?
it's not so much the delay, that's essential, but more the hidden functionality inside waitkey.
imshow will just copy the image, but waitkey will finally blit it ( or , send out the messages to your os nessecary for doing so )
so you need to call waitkey in any case, if you use imshow. 1(millisecond) is the smallest value you can put here for continuous rendering, 0 or -1 will block until you press a key.
besides, waitkey listens to keypresses in that img-window, cin listens to input from the console window.
cv::WaitKEy(0) the image will stay there
Related
I am working on a pexpect script that is running populating an output file name and then a prompt for the file's parameters.
The program that the script runs asks for Device: then Parameters: always on the same line.... so if the file path-name that is entered for Device is long, sometimes the Parameters prompt wraps to the next line.
My code looks like..
child.expect_exact('Device:')
child.sendline('/umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
child.expect_exact('Parameters:')
This times out.. and here is what is in child.before
' /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT Param\r\neters: "RWSN" => '
so the expect fails... (a child.expect('Parameters:') also fails)
How can I ignore the \r\n if it is there, because depending on the length of the path/filename I am using it may not be there at all, or be in a different position.
Thanks!
Actually... I found a way to calculate how much is left on the given line, and dynamically set my expect to how much of the Parameter prompt should be visible... seems to be working
#look for end of line and fix how much of 'Parameters:' we look for in pexpect
dlen = 80-len('Device: /umcfiles/ftp_dir/ftp_peoplesoft/discount/AES_DISCOUNT_15010.TXT')
pstr='Parameters:'
if dlen > len(pstr):
dlen=len(pstr)
else:
dlen=dlen-3 #remove the /r/n
child.expect(pstr[0:dlen])
Exploring F# with FSharp.Charting I thought I would start with a simple 'hello world' but it leaves me with more questions then lines of code.
#load #"..\packages\FSharp.Charting.0.90.14\FSharp.Charting.fsx"
open FSharp.Charting
let chart = Chart.Line([ for x in 0 .. 10 -> x, x*x ])
chart.ShowChart()
chart.SaveChartAs(#"C:\Temp\chart.png",ChartTypes.ChartImageFormat.Png)
This works in interactive window in VS, but what I want to do is execute this script from the cmd line (using fsi.exe). I made an association with fsx files to fsi, but when I execute it it opens fsi but no chart is created. What do I need to do?
Short answer: add the following line at the end of your program:
System.Windows.Forms.Application.Run()
Long answer:
The chart does get created, but it immediately disappears, because your program immediately exits, right after creating the chart. This does not happen in the F# Interactive window in Visual Studio, because the F# interactive window doesn't close immediately after executing your program - it just hangs out there, waiting for you to submit more code for execution.
In order to make your program not exit immediately, you could implement some waiting mechanism, such as waiting for a set amount of time (see System.Threading.Thread.Sleep) or waiting for the user to press Enter (via stdin.ReadLine()), etc.
However, this won't actually help you, because there is the next problem: the chart is drawn via Windows Forms, which relies on the message loop running - otherwise the window can't receive messages, and so can't event paint itself.
FSI does have its own built-in event loop, and this is how your program works under VS. However, if you implement a "waiting" mechanism (e.g. stdin.ReadLine()), this event loop will be blocked - won't be able to pump messages. Therefore, the only sane way to keep your program from exiting, while not interfering with the functioning of the chart window, is to start your own event loop. And this is exactly what Application.Run() does.
Saving to disk without displaying:
(in response to comment)
From what I understand, the FSharp.Charting library was intended as a quick-and-dirty way to display charts on the screen, primary use case being exploring datasets live within F# Interactive. More specifically, some key properties of the Chart object, such as ChartAreas and Series are not initialized upon chart creation, but only when it is shown on the screen (see source code), and without these properties the chart remains empty.
Short of submitting a pull request to the library, I recommend dropping down to the underlying System.Windows.Forms.DataVisualization.Charting.Chart:
open System.Windows.Forms.DataVisualization.Charting
let ch = new Chart()
ch.ChartAreas.Add( new ChartArea() )
let s = new Series( ChartType = SeriesChartType.Line )
s.Points.DataBind( [for x in 1..10 -> x, x*x], "Item1", "Item2", "" )
ch.Series.Add s;
ch.SaveImage(#"C:\Temp\chart.png", System.Drawing.Imaging.ImageFormat.Png)
I want to show images and videos in Scilab using a GUI made in Tcl/Tk.
Scilab has support for Tcl/Tk :- https://help.scilab.org/docs/6.0.0/en_US/section_a10b99d9dda4c3d65d29c2a48e58fd88.html.
I have made a tcl script which displays an image when run from the terminal.
image create photo img -file <filepath>
pack [label .mylabel]
.mylabel configure -image img
However when I write the following .sci file in scilab, it executes successfully but no image window is shown.
function sampletry()
TCL_EvalFile(<path_to_tcl_file>);
endfunction
I do know that the code executed successfully because when I execute the same function again in scilab, I get an error saying that the label .mylabel already exists in the parent window.
Is there any way that I can show images/videos in Scilab using this method or any other method in Scilab? I'm using OpenCV to read the image and return it back to Scilab through the Scilab Api in a list.
The problem is that you're not servicing the event loop from your Scilab code, without which the flurry of messages from the OS to do with actually putting the window on the screen never get through and handled. Assuming you want your code to stop and wait for the viewing to be done, you can just change the Tcl/Tk code to be:
image create photo img -file <filepath>
if {![winfo exists .mylabel]} {
pack [label .mylabel]
}
.mylabel configure -image img
wm deiconify .
# Wait for the user to ask for the window to be closed
wm protocol . WM_DELETE_WINDOW {set done 1}
vwait done
# Process the close immediately
wm withdraw .
update
There's nothing very special about the done variable. We're just waiting for it to be set in the callback. I've added a bit of extra code to allow you to call this twice (i.e., conditionally creating the widget, ensuring that . is displayed and then hiding it at the end).
The simplest technique if you don't want to keep everything in the same process is to run your original script as a separate program, effectively doing:
wish <path_to_tcl_file>
I don't know what the easiest way to do that from Scilab is.
Ok so I have been trying to get bar code scanning to work in a delphi application for the last 3 weeks now. Ive been directed to this example but that example uses other librarys like imagemagika and is a console application. I am looking for a vcl forms application.
Here is some code I have written to try and see if I can get the ZBar processor to work in delphi :
// Create Processor
processor := zbar_processor_create(0);
zbar_processor_set_config(processor, ZBAR_NONE, ZBAR_CFG_ENABLE, 1);
// Initialize processor
zbar_processor_init(processor, {what do I put here ?}, 1);
// Setup a callback
{I dont know what do here}
// Enable preview window
zbar_processor_set_visible(processor, 1);
zbar_processor_set_active(processor, 1);
This code is based on a example in C that I found here : https://github.com/ZBar/ZBar/blob/master/examples/processor.c
as well as the documentation over here :
http://zbar.sourceforge.net/api/zbar_8h.html#c-processor
The zbar window opens but it does not show the video feed because I parsed nil as a paramater in the initialize step. In the example they have this C code but I have no idea what it means :
const char *device = "/dev/video0";
/* initialize the Processor */
if(argc > 1)
device = argv[1];
zbar_processor_init(proc, device, 1);
If I parse '/dev/video0' instead of nil the video feed still doesn't show. So I guess my question is what do I need to parse in zbar_processor_init() function ?
I also dont know how to set up a callback function that will be called once a result is found. How would I go about doing this ?
Thanks in advance,
Kobus
argc is the number of parameters passed in the command line and argv fetches them. dev/video is linux style device. Try con:
zbar_processor_init(processor, 'con:', 1)
Con: is the console. Com1: serial port 1, Aux: auxiliary port - probably usb, Prn: the printer Lpt: the line printer.
Is there a way to set the execution point while debugging Xcode/lldb? To be more specific, after hitting a breakpoint, moving the execution point manually to another line of code?
If you're looking at moving it up or down with in a method you can click and drag the green arrow to a specific point. so if you want to back up a line before the breakpoint. click on the green arrow that is produced and drag it up. If you hit run you'll hit your breakpoint again
In Xcode 6, you can use j lineNumber - see documentation below:
(lldb) help j
Sets the program counter to a new address. This command takes 'raw' input
(no need to quote stuff).
Syntax: _regexp-jump [<line>]
_regexp-jump [<+-lineoffset>]
_regexp-jump [<file>:<line>]
_regexp-jump [*<addr>]
'j' is an abbreviation for '_regexp-jump'
One of the great things about lldb is that it's easy to extend it with a little bit of python scripting. For instance, I threw together a new jump command without much trouble:
import lldb
def jump(debugger, command, result, dict):
"""Usage: jump LINE-NUMBER
Jump to a specific source line of the current frame.
Finds the first code address for a given source line, sets the pc to that value.
Jumping across any allocation/deallocation boundaries (may not be obvious with ARC!), or with optimized code, quickly leads to undefined/crashy behavior. """
if lldb.frame and len(command) >= 1:
line_num = int(command)
context = lldb.frame.GetSymbolContext (lldb.eSymbolContextEverything)
if context and context.GetCompileUnit():
compile_unit = context.GetCompileUnit()
line_index = compile_unit.FindLineEntryIndex (0, line_num, compile_unit.GetFileSpec(), False)
target_line = compile_unit.GetLineEntryAtIndex (line_index)
if target_line and target_line.GetStartAddress().IsValid():
addr = target_line.GetStartAddress().GetLoadAddress (lldb.target)
if addr != lldb.LLDB_INVALID_ADDRESS:
if lldb.frame.SetPC (addr):
print "PC has been set to 0x%x for %s:%d" % (addr, target_line.GetFileSpec().GetFilename(), target_line.GetLine())
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f %s.jump jump' % __name__)
I put this in a directory where I keep Python commands for lldb, ~/lldb/, and I load it in my ~/.lldbinit file with
command script import ~/lldb/jump.py
and now I have a command jump (j works) which will jump to a given line number. e.g.
(lldb) j 5
PC has been set to 0x100000f0f for a.c:5
(lldb)
This new jump command will be available both in command-line lldb and in Xcode if you load it in your ~/.lldbinit file -- you'll need to use the debugger console pane in Xcode to move the pc instead of moving the indicator in the editor window.
You can move the program counter (pc) in lldb using the lldb command register write pc. But it's instruction based.
There's an excellent lldb/gdb comparison here that is useful as an lldb overview.