Tuesday, 20 September 2011
NiViewer
Today I ran NiViewer provided by OpenNI again on Captured_08_22_11.oni, and observed vertical lines on the depth image. The vertical lines also shift with time.
The default coloring of the depth image is according to linear histogram. MAX_DEPTH is set to be 10000. The histogram is calculated according the following steps (in Draw.cpp, line 549, calculateHistogram()):
- Count the number of pixels with the same depth_value and store it in depthHist[depth_value].
- Calculate the accumulative frequency.
- Invert the accumulative frequency.
In this way, pixels with greater depth values will have darker color. The use of histogram is good because the color is not scaled linearly with depth but with the frequency of the occurrences of the depth values.
Sunday, 18 September 2011
Ruby and Python boolean expressions compared
Ruby:
Only
The word forms of the logical operators (
Equality testing:
Ruby has three main equality test methods,
Python:
More values are considered false in Python:
In Python,
To check if an object is an instance of a type (class), use
Only
false
and nil
are treated as being false in a boolean context. All other values are treated as being true.and
, &&
, or
, and ||
all return operands. Bot and
and &&
return their first argument if it is false. Otherwise, they evaluate and return their second argument. Similarly, both or
and ||
return their first argument unless it is false, in which case they evaluate and return their second argument.The word forms of the logical operators (
and
, or
and not
) have a lower precedence than the corresponding symbol forms (&&
, ||
, and !
).Equality testing:
Ruby has three main equality test methods,
==
, eql?
and equal?
. They are defined in the Object
class and in the Object
class, all three methods do exactly the same thing, they test if two objects are exactly the same object. However, in other classes, they are usually redefined with different semantics:==
Test for equal valueeql?
True if the receiver and argument have both the same type and equal values.1 == 1.0
returnstrue
, but1.eql?(1.0)
isfalse
.equal?
True if the receiver and argument have the same object ID.
===
, which is used to compare each of the items with the target in the when
clause of a case
statement. The ===
operator is defined in Class
to test whether the argument is an instance of the receiver or one of its superclasses. So you can use it to test the class of objects.Python:
More values are considered false in Python:
None
False
- zero of any numeric type, for example,
0
,0L
,0.0
,0j
. - any empty sequence, for example,
''
,()
,[]
. - any empty mapping, for example,
{}
. - instances of user-defined classes, if the class defines a
__nonzero__()
or__len__()
method, when that method returns the integer zero orbool
valueFalse
.
In Python,
==
is similar to ==
in Ruby for numeric types and different string types (str
and unicode
) in that it only compares the values, but not the types, e.g. 1 == 1.0
returns True
. But for objects of other types, ==
is similar to eql?
in Ruby because both types and values have to be equal for it to return True
. The object identity test is
is the same to equal?
in Ruby.To check if an object is an instance of a type (class), use
isinstance(object, type_name)
.Monday, 12 September 2011
XHR2
Recently I used XHR2 for the CSSA new website. Basically, XHR2 enhances XHR with new features, such as cross-origin requests. This means you can make an XHR request across domains, but only if the server you're connecting to allows it.
This means the server needs to respond with a CORS (Cross-Origin Resource Sharing) header. For PHP, you can add the following lines at the beginning of the .php file:
'*' means it allows any origin to access the resource.
References:
https://developer.mozilla.org/en/HTTP_access_control#Access-Control-Allow-Origin
http://html5doctor.com/methods-of-communication/
This means the server needs to respond with a CORS (Cross-Origin Resource Sharing) header. For PHP, you can add the following lines at the beginning of the .php file:
<?php header('Access-Control-Allow-Origin: *'); ?>
'*' means it allows any origin to access the resource.
References:
https://developer.mozilla.org/en/HTTP_access_control#Access-Control-Allow-Origin
http://html5doctor.com/methods-of-communication/
Labels:
ajax
,
web programming
Subscribe to:
Posts
(
Atom
)