Surface normal on depth image

How to estimate the surface normal of point I(i,j) on a depth image (pixel value in mm) without using Point Cloud Library(PCL)? I've gone through (1), (2), and (3) but I'm looking for a simple estimation of surface normal on each pixel with C++ standard library or openCV.





Answers

You need to know the camera's intrinsic parameters, so that you can also know the distance between pixels in the same units (mm). This distance between pixels is obviously true for a certain distance from the camera (i.e. the value of the center pixel)



If the camera matrix is K which is typically something like:



    f  0  cx
K= 0 f cy
0 0 1


Then, taking a pixel coordinates (x,y), then a ray from the camera origin through the pixel (in camera world coordinate space) is defined using:



              x
P = inv(K) * y
1


Depending of whether the distance in your image is a projection on the Z axis, or just a euclidean distance from the center, you need to either normalize the vector P such that the magnitude is the distance to the pixel you want, or make sure the z component of P is this distance. For pixels around the center of the frame this should be close to identical.



If you do the same operation to nearby pixels (say, left and right) you get Pl and Pr in units of mm
Then just find the norm of (Pl-Pr) which is twice the distance between adjacent pixels in mm.



Then, you calculate the gradient in X and Y



gx = (Pi+1,j - Pi-1,j) / (2*pixel_size)


Then, take the two gradients as direction vectors:



ax = atan(gx),  ay=atan(gy)


| cos ax 0 sin ax | |1|
dx = | 0 1 0 | * |0|
| -sin ax 0 cos ax | |0|

| 1 0 0 | |0|
dy = | 0 cos ay -sin ay | * |1|
| 0 sin ay cos ay | |0|

N = cross(dx,dy);


You may need to see if the signs make sense, by looking at a certain gradient and seeing of the dx,dy point to the expected direction. You may need to use a negative for none/one/both angles and same for the N vector.





PHP FTP Upload function

i have this function in PHP:



function UploadFileToFTP($local_path, $remote_path, $file, $filename) {
global $settings;

$remote_path = 'public_html/'.$remote_path;

$ftp_server = $settings["IntegraFTP_H"];
$ftp_user_name = $settings["IntegraFTP_U"];
$ftp_user_pass = $settings["IntegraFTP_P"];

//first save the file locally
file_put_contents($local_path.$filename, $file);

//login
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
}

//change directory
ftp_chdir($conn_id, $remote_path);
$upload = ftp_put($conn_id, $filename, $local_path.$filename, FTP_BINARY);

// check upload status
if(!$upload) {
echo "FTP upload has failed!";
}
// close the FTP stream
ftp_close($conn_id);
}


i call it here:



UploadFileToFTP('p/website/uploaded_media/', 'media/', $_FILES["file"]["tmp_name"], $filename);


the selected file is being moved into the local directory and also being uploaded to FTP however the file is becoming corrupt because it is not being uploaded correctly.



how can i get the file uploading properly?



Answers

Depending on what kind of file you're moving you may need to switch from FTP_BINARY to FTP_ASCII



http://forums.devshed.com/ftp-help-113/ftp_ascii-ftp_binary-59975.html



Answers

When uploading a file to PHP it stores the uploaded file in a temporary location, the location is stored in $_FILES["file"]["tmp_name"].



You are then passing that value into your UploadToFTP function as the variable $file.



Then you try to save a copy of the uploaded file:



//first save the file locally
file_put_contents($local_path.$filename, $file);


What this will do is write the string contained within $file (i.e. the path of the temp file) to your new location - but you want to write the content of the file.



Instead of using file_put_contents use move_uploaded_file:



move_uploaded_file($file, $local_path.$filename);




Programmatically set the text of a select - jquery

I need to programmatically set an option of an existing select box when I only know the text of the option and not the value.



Here is my code:



$("#" + eventQuestions[x].code).find('option[text="' + eventAnswers[x].vAnswerString + '"]').attr("selected");


Don't focus too much on selecting the right html element or the right text being inside the vAnswerString - I can confirm those are correct.



Basically the option is not being selected. What is wrong with my code?



Answers

Check out this answer.



You can use that filter to check the inner text and then you put the selected attribute like this:



.attr("selected", true);


Example I tested it with:



$(function() {
$("#select").find("option").filter(function() {
return this.innerHTML == "InnerText";
}).attr("selected", true);
})


Answers

Here is a working example for jquery 1.6+.



Select the option using the filter function:



var text = "theTextToFind";
var matchingOption = $("select#myselect option").filter(function () {
return $(this).text() == text;
});


Set the value using the property function:



matchingOption.prop('selected', true);


Also check out this Answer.





↑このページのトップヘ