Monday, October 22, 2012

PCA Dimension Reduction In Matlab


X = columnwise_vector';
%row-wise [X rows are the number of samples and cols are the number of dimensions]

C = mean(X);
X = X - repmat(C, size(X,1),1); %normalize by removing mean

covar = cov(X); %compute covariance matrix

[p,D]=eigs(covar, numDim);

X_reduced = (X*p);
X_reduced = X_reduced';

Friday, October 19, 2012

Hardware synchronizing a stereo rig of ps3 eye usb cameras

2 Links:

http://www.instructables.com/id/The-EyeWriter-20/?ALLSTEPS
http://nuigroup.com/forums/viewthread/12445/#66879

Thursday, October 18, 2012

Viewing stereo usb cameras on ROS

Download and install the uvc_camera drivers

Edit the uvcCameraLaunch.launch to contain the following:
<!--xml-->
<launch>
      <node pkg="uvc_camera" type="stereo_node" name="uvc_camera_stereo">
        <param name="width" type="int" value="320" />
        <param name="height" type="int" value="240" />
        <param name="fps" type="int" value="30" />
        <param name="frame" type="string" value="wide_stereo" />
    <param name="right/device" type="string" value="/dev/video1" />
        <param name="left/device" type="string" value="/dev/video2" />
     </node>
</launch>

launch this stack by:  ROS_NAMESPACE=stereo roslaunch UAVcam uvcCameraLaunch.launch

View the published messages: rostopic list
make sure the ros_namespace precedes the /left and /right image stream messages.

To view each stream:
$ rosrun image_view image_view image:=/stereo/left/image_raw
$ rosrun image_view image_view image:=/stereo/right/image_raw 
If you have a built-in webcam, I disabled it using the following:
by adding "blacklist uvcvideo" to the end of the file /etc/modprobe.d/blacklist.conf
I made sure uvcvideo was the name of the driver being used for this webcam using hwinfo 
(you must restart for the webcam to be disabled)
 
Then run the camera_calibration.
http://www.ros.org/wiki/camera_calibration/Tutorials/StereoCalibration 
 
 
 
 




Wednesday, October 17, 2012

ps3 eye usb camera and ROS

How to work with playstation ps3 eye USB camera and ROS and OpenCV

http://siddhantahuja.wordpress.com/2011/07/20/working-with-ros-and-opencv-draft/

For stereo:
https://code.ros.org/gf/project/ros/mailman/?_forum_action=ForumMessageBrowse&thread_id=55017&action=ListThreads&mailman_id=20

roscd: command not found

Problem:
roscd: command not found

Solution:
To solve this problem you must define the source of the ros setup.bash file:
Execute:

- source /opt/ros/fuerte/setup.bash
- source ~/ros_workspace/setup.bash 

(the second one made all warnings go away - use this instead of the first one. With the first one, I still got some warnings when I typed roscd with no arguments) 

in a terminal. In my case I was working ROS Fuerte (version 1.8.10).

this happened because I didnt do the last steps of installing ROS.

For a permanent fix edit .bashrc (use 'gedit .bashrc" for editing)and add the following to the end of the file:

export ROS_WORKSPACE=/home/anubis/fuerte_workspace









notice that we changed the ros workspace name (from ros_workspace to fuerte_workspace)

Friday, September 7, 2012

Setting Mat Pixels (elements) in OpenCV


This is how you set individual element's color channels of a Mat structure in OpenCV

img.at<cv::Vec3b>(v,u)[0]=B;
img.at<cv::Vec3b>(v,u)[1]=G;
img.at<cv::Vec3b>(v,u)[2]=R;

Thursday, August 9, 2012

Play Video in OpenCV

This is with the older OpenCV versions. I had problems using the new OpenCV 2.4.0 so I resorted to this older way of reading videos. It can also be used in the later OpenCV versions (i.e. they are backward compatible)


/* play a video file */

#include <highgui.h>

int main(int argc, char** argv) {
    /* Create a window */
    cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
    /* capture frame from video file */
    CvCapture* capture = cvCreateFileCapture( argv[1]);
    /* Create IplImage to point to each frame */
    IplImage* frame;
    /* Loop until frame ended or ESC is pressed */
    while(1) {
        /* grab frame image, and retrieve */
        frame = cvQueryFrame(capture);
        /* exit loop if fram is null / movie end */
        if(!frame) break;
        /* display frame into window */
        cvShowImage("Example2", frame);
        /* if ESC is pressed then exit loop */
        char c = cvWaitKey(33);
        if(c==27) break;
    }
    /* destroy pointer to video */
    cvReleaseCapture(&capture);
    /* delete window */
    cvDestroyWindow("Example2");

    return EXIT_SUCCESS;
}

Adding OpenCV to Eclipse

Adding OpenCV to Eclipse:


  1. Download eclipse indigo or the latest C++ IDE version
  2. Create a project
  3. Properties > C/C++ Build > Settings. 
  • Under Libraries add "opencv_core", "opencv_cv" and all OpenCV libraries you will need
  • Under "Library Search Path" add the location of the built libraries, usually: "/usr/local/lib" on Mac
  • Under Includes add the path to the include header files (.h), usually: "usr/local/include/opencv"