cvShowImage my image color was changed - visual-c++

I got strange condition when showing my video using cvShowImage or even when appending image data on IPLImage, I'm not quite sure.
The image/frame should be like this:
but the imaged was displayed like this:
As you can see, some parts of frame are also moved to the leftside.
Is there anyone encounter similar issue?
while(1){
m_IPLimg1 = m_pFrameCapture->GrabOneFrame();
if(m_IPLimg1 == NULL) break;// no more frames, exit the loop
cvFlip(m_IPLimg2, NULL, 0 );
cvShowImage("Original Video", m_IPLimg1);
cvShowImage("GMM Result Video", m_IPLimg2);
char c = cvWaitKey(20);
if (c==27) break;
}
Really thanks in advance.

It looks like you're trying to flip m_IPLimg2 in place but are not setting its contents first. Try:
cvFlip(m_IPLimg1, m_IPLimg2, 0 );
This will flip m_IPLimg1 and place the results into m_IPLimg2.

I got the solution, I need to format my .avi first using mencoder , since the video above I generated from image sequence, the codec seems broken. Thanks for all responses however.

Related

formatting text output in terminals

I'm currently writing a command line tool for myself, that needs to print some information on the terminal. I'm a little annoyed of the whole formatting. Here is my example.
formatter = logging.Formatter(fmt = '%(message)s')
console_logger = logging.getLogger("console_logger")
console_logger.setLevel(logging.DEBUG)
console_logger_handler = logging.StreamHandler()
console_logger_handler.setFormatter(formatter)
console_logger.addHandler(console_logger_handler)
console_logger.propagate = False
here goes some further code and then I have the printing function
for element in open_orders:
console_logger.info("Type: {}, Rate: {}, amount: {}, state: {}, pair: {}/{}, creation: {}, id: {}".format(element.type,
element.rate,
element.amount,
element.state,
element.currency_pair.get_base_currency().upper(),
element.currency_pair.get_quote_currency().upper(),
creation_time,
element.order_id))
I rather would like to have this as a column where the output is aligned at the colon. after each element a line of underscores or minusses would be nice as well, this should respect terminal width. I know this can be hardcoded in some manner, but isn't there a better way? Some kind of templating engine that can handle multiline output?
EDIT:
So here is an example:
Type : buy
Rate : 1234
amount : 1
state : active
pair : usd/eur
creation : 2017.12.12
I know this can be printed line by line with format but I need to determine the length of the longest string on my own and I was wondering if there isn a framework or something more elegant doing this for me.
id : 123456
Use format, add with your data :
for element in open_orders:
console_logger.info("Type: {:25s}, Rate: {:25s}, amount: {:07.2f}, state: {:25s}, pair: {:25s}/{:25s}, creation: {:25s}, id: {:25s}".format(element.type,
element.rate,
element.amount,
element.state,
element.currency_pair.get_base_currency().upper(),
element.currency_pair.get_quote_currency().upper(),
creation_time,
element.order_id))
You can also visit this site : https://pyformat.info/
In addition, you could try to use Colorama.
You have to install it, tipically, from pypi.
It allows you to handle cursor positioning, so you can control in which position at the screen (terminal) you want to print data, using "coordinates". Also, you can apply colors to text, which could give you a cleaner and prettier look if you want to.
So what I finally found which helps a lot at least in case of lists and formatting of them is this
terminaltable

Finding string in the textfield. Actionscript

What is the best way to find a string (sentence of 1-3 lines) in the multiline textfield.
I have a textfield with a list of messages. In order to change every second messages color, i have to get the index where this message beggins.
ANy ideas?
I solved my problem. Maybe it will be useful for someone.
As i'm appending text, i use textfield.caretIndex to see the inserts. So i'm switching formats using this function:
if (i % 2 != 0) {
textfield.setTextFormat(colorFormat, lastCaret , textfield.caretIndex);
formatStart = textfield.caretIndex;
}
else {
textfield.setTextFormat(textFormat, formatStart, textfield.caretIndex);
lastCaret = textfield.caretIndex;
}

headerlinesIn not working correctly in importdata MATLAB

I am importing some data from the excel and the code looks like this:
Code:
%Import Data
filename = 'Stocks.xlsx';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
The excel file looks like this:
When I read in the data, A looks like this:
I thought when the headerlineIn = 1, the first line should not read. Why is it that it is being read? How to avoid this?
Need some guidance..
How I thought your code is alright.
With your example file and your code I get a struct A.
A = importdata('Stocks.xlsx',' ',1);
In A.data.Sheet1 is all the data correctly read:
And in A.textdata.Sheet1 the appears what you posted you get.
So the problem must be something I can't reproduce.
Alternatively you could try if xlsread works for you.
B = xlsread('Stocks.xlsx',1)
I get the same result as before.
I finally get your problem, you're not concerned about the data, you really want to skip the first line of the header in the means of textdata.
Well headerlinesIn just signalizes importdata when your data starts, respectively when it should start to read actual data. Everything else, which is then declared not to be data, is put into A.textdata.Sheet1, also the first line. So the code works as intended.
If you want to get rid of the first line of your header, you could apply the following line:
N = 2; %// number of columns before data starts
A.textdata.Sheet1 = {A.textdata.Sheet1{headerlinesIn+1:end,1:N}};

Playn text wrapping and style issue

As in Effect.shadow() is deprecated in PlayN1.3.So i had something like this before :
TextFormat textFormat = new TextFormat(myFont, textWidth, Alignment.LEFT, colorCode, Effect.shadow(-16777216, shadowX, shadowY));
So i changed it to this :
TextFormat textFormat = new TextFormat();
textFormat.withFont(myFont);
textFormat.withWrapping(textWidth, Alignment.LEFT);
I dont want shadow now.It's ok but i did not get previous like result.Hold on.dont think now.Then i changed this code to this:
TextFormat textFormat = new TextFormat().withFont(myFont).withWrapping(textWidth, Alignment.LEFT);
It gives me result as previous except shadow which i dont care now.If i am not wrong this is one line representation of above code.Is not it?
So why it worked and above code did not.Any conceptual difference is there? Anyone can explain please!
//note: dont worry about variables(textWidth,myFont)they are nothing to do with this.
TextFormat objects are immutable. When you call textFormat.withFont(myFont) that returns a new TextFormat instance, which the code above is throwing away. If you want the first code to work you need to write it like this:
TextFormat format = new TextFormat();
format = format.withFont(myFont);
format = format.withWrapping(textWidth, Alignment.LEFT);

Wireshark dissector in Lua - userdata

I am new to Lua, and I am building a custom dissector for Wireshark. My situation is this:
The wireshark data consists of hex numbers such as 4321 8765 CBA9. What I would like to wind up with is (after it has been dissected) : CBA9 8765 4321.
What I have done so far is create a small function in Lua that will take these numbers individually, convert them to strings, and places them in the correct order.
function ReverseOrder3Numbers(hex_1, hex_2, hex_3)
local hex_1_int = hex_1:uint()
local hex_2_int = hex_2:uint()
local hex_3_int = hex_3:uint()
word1 = string.format("%04X", hex_1_int)
word2 = string.format("%04X", hex_2_int)
word3 = string.format("%04X", hex_3_int)
combined_string = "0x" .. word3 .. word2 .. word1
output = combined_string
return output
end
However, once I go to add this bunch to the tree, I get an error saying Lua Error: ...: calling 'add' on bad self (userdata expected, got string).
How can I get around this? Do I need a different approach entirely? I am not looking for anything complex or fancy. All I need to do is what I described. Any help would be appreciated.
There's nothing really wrong with ReverseOrder3Numbers (other than perhaps some missing local qualifiers). You should update your question to include the code that invokes add.
You might've accidentally used tree.add( ... ) instead of tree:add( ... ) (note the colon after tree).
Call tree:add() will send to the object 'tree' the direct link to 'tree' itself as first implicitly argument. And no matter how much args you will attach to this call or no one at all. Use tree.add() sintax if your 'add' method doesn't support self-link. In this case 'self' should be linked to the 'tree' object inside the 'add' method.
It's not clear what you pass to the function ReverseOrder3Numbers. But since you access theses parameeters with the uint method I assume that the parameters are tvb:range(x,y) results. If you want to change the order of the digits inside the individual values, you can use the endianess-aware methods:
function ReverseOrder3Numbers(hex_1, hex_2, hex_3)
local hex_1_int = hex_1:le_uint()
local hex_2_int = hex_2:le_uint()
local hex_3_int = hex_3:le_uint()
...
end
If you want to change the endianess of data that is added to the tree you should use the endianess-aware version of the add method.
tree:le_add(f_MyProtoField, tvb:range(x,y), ReverseOrder3Numbers(...))
I don't know the reason why le is suffix in the one case and a prefix in the other.

Resources