Sunday, October 31, 2010

The future of computer vision: in user interfaces

This company is just bought by Microsoft.


Wednesday, October 20, 2010

Clean Up MP3 Filenames

import os

base = '/home/maczulu/Music'
os.chdir(base)
filelist = os.listdir(base)
for file in filelist:
  if '_' in file:
    newname = file.replace('_',' ')
    print file,newname
    os.rename(file, newname)

GNOME of course!

Monday, October 18, 2010

Convert IPLImage (OpenCV) to QImage (Qt) vice versa

This snippet will convert QImages into iplImage with depth 8 and 3 channels. QImage can store data in several formats. This code accepts just 24-bit QImage::Format_RGB888 and the QImage::Format_RGB32. Alpha values in the 32-bit format will be removed during the conversion.

static IplImage* qImage2IplImage(const QImage& qImage)
{
  int width = qImage.width();
  int height = qImage.height();
  // Creates a iplImage with 3 channels
  IplImage *img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
  char* imgBuffer = img->imageData;
  //Remove alpha channel
  int jump = (qImage.hasAlphaChannel())? 4 : 3;
  for(int y=0;yheight;y++){
    QByteArray a((constchar*)qImage.scanLine(y), qImage.bytesPerLine());
  for(int i=0; i<a.size(); i+="jump){
    //Swap from RGB to BGR
    imgBuffer[2]= a[i];
    imgBuffer[1]= a[i+1];
    imgBuffer[0]= a[i+2];
    imgBuffer+=3;
  }
}
return img;

This snippet will convert a iplImage with depth 8 and 3 channels into a 24-bit QImage.

static QImage IplImage2QImage(const IplImage *iplImage) 
{ 
  int height = iplImage->height; 
  int width = iplImage->width; 
  if (iplImage->depth == IPL_DEPTH_8U && iplImage->nChannels == 3) 
  { 
      const uchar *qImageBuffer =(const uchar*)iplImage->imageData; 
      QImage img(qImageBuffer, width, height, QImage::Format_RGB888); 
      return img.rgbSwapped(); 
  }else{ 
    qWarning() << "Image cannot be converted."; 
   return QImage(); 
  } 
} 


http://wiki.forum.nokia.com/index.php?title=Special:PdfPrint&page=Using_OpenCV_with_Qt

Another method here:

http://umanga.wordpress.com/2010/04/19/how-to-covert-qt-qimage-into-opencv-iplimage-and-wise-versa/

Do they work for you?
Please leave a comment.

Tuesday, October 12, 2010

Good Features to Track using OpenCV and Python

import cv

filename =  "burke94.jpg" # replace w/ your filename
grayImage = cv.LoadImage(filename, 2)
eigImage = cv.CreateImage(cv.GetSize(grayImage), cv.IPL_DEPTH_32F, 1)
tempImage = cv.CreateImage(cv.GetSize(grayImage), cv.IPL_DEPTH_32F, 1)

cornerMem = []
cornerCount = 300
qualityLevel = 0.1
minDistance = 5
cornerMem = cv.GoodFeaturesToTrack(grayImage, eigImage, tempImage,  cornerCount, qualityLevel, minDistance, None, 3, False)

print len(cornerMem), " corners found"
print cornerMem


for point in cornerMem:
    center = int(point[0]), int(point[1])
    cv.Circle(colorImage, (center), 2, (0,255,255))
cv.SaveImage("savedcolor.jpg",colorImage)

Laplacian filter using OpenCV and Python

import cv

# Load the image, replace filename with any JPG you like
img = cv.LoadImage("olympus.jpg")
# create buffer for grayscle
tmp = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_8U, 1)
#  convert color to grayscale
cv.CvtColor(img, tmp, cv.CV_BGR2GRAY)
# create destination buffer
dst = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_32F, 1)
# execute the filter: 3rd parameter is mask size, default = 3
cv.Laplace(tmp, dst)
# save image to disk
cv.SaveImage("saved.jpg", dst)

You can shorten the code by converting to grayscale on the fly like so:
import cv

img = cv.LoadImage("olympus.jpg", 2)
dst = cv.CreateImage(cv.GetSize(img), cv.IPL_DEPTH_32F, 1)
cv.Laplace(img, dst) # 3rd parameter is mask size, default = 3
cv.SaveImage("saved.jpg", dst)
Instead of saving to disk, you may want to display the result on a new window. Not shown here..

Replacing Panasonic HDD in Panasonic DVD Recorder

Minggu lepas, Panasonic DVD recorder tiba-tiba tak mau rakam. Dah sah hard disk rosak. Habislah rakaman Shin Chan dan Doraemon yang dikumpul beberapa tahun tu. Cari punya cari, terjumpa posting yg kata boleh ganti dengan sebarang hard disk IDE. Ada hard disk spare, maka terjadilah projek 15 minit berikut.

DVD recorder dari luar.

Part number DMR EH-60.

DVD recorder setelah dibuka.

Hard disk yang rosak: Western Digital 200GB. Memang brand ni kurang baik.

Hard disk baru: Hitachi 320GB.

DVD recorder setelah dipasang HDD baru.

Operasi format HDD baru.

Kapasiti 200GB ialah 355 jam EP mode. Tapi default mode ialah SP.

Setelah diformat, hanya 200GB digunakan dari 320GB disebabkan saiz telah ditetapkan oleh firmware. Dengan 200GB, masa rakaman dalam SP mode ialah 184 jam. Darab 2 utk EP mode iaitu lebih kurang 355 jam.