Tuesday, March 2, 2010

Eclipse Copy Shortcut

Ever want to have something saved in the clipboard and still be able to copy/paste other information?  Well in Eclipse there is a very handy feature for such a thing.  Follow these easy steps:
  1. Copy some text into your clipboard (e.g. CTRL C)
  2. Highlight your second text
  3. Middle click where you want the second text to be pasted (or left click first and then middle click)

Monday, February 22, 2010

Blob Analysis Introduction

I did a presentation on blob analysis a couple years back. I think it is an important topic that I enjoyed learning about. I covered blob analysis and a brief amount of morphology.  Another student covered that in depth so there is not too much info there.  Information on this topic can be found online, but actual algorithms for many of the ideas was tough to find.

Blob Analysis
    - This is taking an image, thresholding it to black and white (binary) only and then using this to make decisions or take measurements.

   Examples:
   Centroid - Find the center of a blob object
   Size - Find the size of a blob object
   Amount - Finds the amount of blobs in the image
   Extent - Find the extent of an image (usually grouping is a good method)

Morphology
   - This is used on a black/white image to enhance the image.  Of course you can apply some of these techniques to enhance the image prior to making the image binary (color or greyscale). 

   Examples:
   Erosion - This shrinks blob objects
   Dilation - This grows blob objects
   Watershed - This helps find edges
   Boundary Extraction - This helps find edges

I plan on going into each section in more detail when I get the chance.  For now here is the presentation that I made for my class. 
 

C++ Code for Minimum Value

Here is some code that I wrote while learning about vectors and templates.  The code takes a large sequence of numbers and finds the smallest value for a smaller segment of the larger sequence.  This is repeated for each small segment that fits into the larger segment.

Example:
   We have a large sequence (size 20) and want to find the minimum value for each small segment (size 5).

Large Sequence:
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

1st Small Sequence               Output
 1 2 3 4 5                                   1

2nd Small Sequence              Output
 6 7 8 9 10                                 6

3rd Small Sequence               Output
 11 12 13 14 15                         11

4th Small Sequence               Output
 16 17 18 19 20                         16
 Code:
    Here is the code

Wednesday, February 17, 2010

How to update a GTK::TextView from a separate object

If you are wondering how to update a text box that was created in your GTK GUI from a separate object then you have come to the right place.  As of this positing date I have searched for the solution to this problem, but there is no real mention on how to do it.  The basic premise is to get the underlying object of the TextView and pass it to the object that wants to edit it.  Then that object must create a pointer to this object and can then access its information.  Anyways lets get to it.

File List:
  • textEdit.cpp - This is where the code is written to update the TextView declared in example.cpp
  • textEdit.h - This is the header file for the code that will update the TextView declared in example.cpp
  • example.cpp - This is where the GUI and TextView are defined

textEdit.h

#include 
using namespace std;

class textEdit{

private:
   GtkTextView *l_text_view;
   Glib::RefPtr l_text_view_buffer;

public:
   textEdit(){l_text_view = NULL; l_text_view_buffer = Gtk::TextBuffer::create();}
   void updateText();
   void setTextViewObject(GtkTextView *text_view){l_text_view = text_view;}
   virtual ~textEdit(){}

}


textEdit.cpp

#include "textEdit.h"

void updateText(){
   string update_words = "Testing, Testing, Testing";

   // Setup a temporary pointer to a TextView
   Gtk::TextView *temp;

   // Get the old buffer and append the new update to it (this can be changed to whatever)
   string bufferNew = update_words + "\n" + l_text_view_buffer->get_text();

  // Set the new buffer text to the actual buffer
  l_text_view_buffer->set_text(bufferNew);

  // Take the l_text_view and assign this pointer to temp
  temp = Glib::wrap(l_text_view,false);

  // Update the temp TextView with the buffer
  temp->set_buffer(l_text_view_buffer);
}


example.cpp

.
.
.

// Create the object
textEdit textEdit;

// Send the text_view object.  This would be defined in you header file as such:
//      Gtk::TextView text_view;
textEdit.setTextViewObject(text_view.gobj)

.
.
.

Tuesday, February 16, 2010

OpenCV 2.0, Windows and Eclipse Setup Instructions

This blog involves the latest release of OpenCV 2.0.  I have concentrated most of my time into developing OpenCV applications in the Linux environment.  This time I wanted to learn how to set it up in Windows with the latest stable release of OpenCV.

Documentation:

This following document involves the setup of Eclipse for OpenCV2.0 in Windows, the installation of all necessary programs to be installed to run OpenCV2.0 in Eclipse, and how to add an existing project.  This document was originally designed for my Professor's Digital Image Processing class at the UNH ECE Department.  The basic setup procedure was created by Jon Carrier over at Carrier Frequency.  This document incorporates images for ease of understanding.

Document: OpenCV2.0 Project Setup in Eclipse.pdf

Sample Code:

This sample code is for someone that wants to get into Image Processing with a minimal setup.  Students of Image Processing classes are encouraged to utilize this code.  I ask that you do not remove the citation information in order to preserve the originality of the work.

What it is:
   This is code that can be imported into Eclipse and run and modified without much effort.

What is does:
   The code opens a camera capture and allows the user to press certain keyboard numbers to toggle between algorithms.  By default the program has 5 settings.
  1. Press the number 1 button to run the Canny edge detector with a specified threshold
  2. Press the number 2 button to run the Canny edge detector with a threshold value of 1
  3. Press the number 3 button to run an algorithm that manipulates at the pixel level to remove the green channel.
  4. Press the ESC key to exit the program
  5. Press any other key to undo all editing settings (default case)
What to do with it:
   Edit the code and make it your own.  For users that do not know much about OpenCV and/or C++ programming the code is very simple and there are great instructions included.  

How to add your own code:
   In the Laboratory.cpp file add a new case to the switch statement.  Just increment the case number and the ASCII value for that value is the button you press to call your function.  Then edit VisionJobs.h to declare a new function.  Then edit VisionJobs.cpp and add your new function there and modify the frames as necessary.

Code:
   Ok lets get to it and let you download the code.

Download location is here (zip file containing all .c and .h files and Eclipse .cproject and .project files)

Tuesday, January 5, 2010

OpenCV libcv.so.2.0 error

Sometimes after a fresh install of OpenCV in a fresh install of Linux you may come across the error:

error while loading shared libraries: libcv.so.2.0: cannot open shared object file: No such file or directory


If you do then follow the instructions provided by an OpenCV thread on nabble.com. Click here