2014年10月30日 星期四

VC++ 2012 opencv error "0xc0000005讀取位置0x00000000時發生存取違規"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv/cv.h>

using namespace cv;
using namespace std;

int main( int argc, char** argv ){
    Mat image;
    image = imread("1.jpg");
    namedWindow( "show window", CV_WINDOW_AUTOSIZE );
    imshow( "show window", image );
    waitKey(0);
    return 0;
}

應該是沒找到圖檔
建置VC++空專案時不要為方案建立目錄
將圖檔放在專案資料夾即可找到圖
x64系統
組態管理員->新增x64平台(來源複製Win32,勾選建立新專案平台

2014年10月15日 星期三

replace string in files

if we want to replace some strings in files of a folder, we can use find, xargs and sed.
for example, i want to change string '/opt/anaconda' to 'home/robot2/anaconda in many files of '/home/robot2/anaconda/bin'.
first, go to the folder
$ cd /home/robot2/anaconda/bin
then, find all files to replace the string
$ find * | xargs -i sed -i 's/\/opt\/anaconda/\/home\/robot2\/anaconda/g' {}
where '/' needs '\' to escape

2014年8月19日 星期二

UBUNTU Hardware Enablement Stack (HWE) out of support & rviz segmentation fault

安裝12.04.5 LTS 更新 Hardware Enablement Stack (HWE)後螢幕黑掉,
原來是我加裝的顯卡7V7300GS可能太舊沒有支援。
使用原本主機板上的顯示晶片就可以了。

另外,在更新前使用ROS rviz 執行時會發生的
#rosrun rviz rviz
compiled against OGRE version 1.7.4 (Cthugha)
segmentation fault (core dumped)
也消失了

不過後來rviz又出現令一個錯誤
Ogre::RenderWindow* rviz::RenderSystem::makeRenderWindow(intptr_t, unsigned int, unsigned int): Assertion `false' failed.

我想是之前顯卡的驅動做怪,找到網路上有人這麼做

sudo apt-get purge nvidia-*
sudo rm /etc/X11/xorg.conf # if the file does not exist , then is OK
sudo apt-get install nvidia-common ubuntu-desktop
sudo apt-get install --reinstall xserver-xorg-video-nouveau
sudo dpkg-reconfigure xserver-xorg
sudo reboot

重開機後 rviz is working

2014年8月1日 星期五

python virtualenv packages path not found

I practice to install django with virtualenv in windows.
When i type "django-admin.py startproject mysite", 
it can not import django.core and the error message is    
" from django.core import management
ImportError: No module named django.core"

find the solution from below link

This is because, it still use the python.exe in default (C:\python27) not the python.exe in my virtualenv (D:\venv\Scripts).

using the ftype to check the Python.file
D:> ftype Python.file

using the ftype to change the Python.file
D:\ftype Python.file = "D:\venv\Scripts\python.exe" "1%" %* 

2014年6月9日 星期一

programing for kid

Blockly
https://code.google.com/p/blockly/

Snap
http://snap.berkeley.edu/

Scratch
http://scratch.mit.edu/

Alice
http://www.alice.org/index.php

2014年3月25日 星期二

weka3.6 with LibSVM

Step 1: download LibSVM
https://github.com/cjlin1/libsvm

Step2: unzip the zip file libsvm-master.zip,
  and then find the libsvm.jar in /where you unzip/libsvm-master/java

Step3: copy libsvm.jar into your Weka folder
  ex: in my path is D:\Weka3-6\

Step4: set up the CLASSPATH in your environment or in RunWeka.ini
in your environment
  in Windows:
    In the Control Panel click on System (or right click on My Computer and select Properties) and then go       to the Advanced tab. There you will find a button called Environment Variables, click it.
    Enter the "CLASSPATH" for the variable and add this value "D:\Weka3-6\libsvm.jar" after ";" if you have     other values in CLASSPATH

  DOS command:
    set CLASSPATH=%CLASSPATH%;D:\Weka3-6\libsvm.jar;

  in Linux:
    export CLASSPATH=$CLASSPATH: where your libsvm.jar
    if i put it in /home/user
    export CLASSPATH=$CLASSPATH:/home/user/libsvm.jar

in RunWeka.ini:
  in Windows:
    open RunWeka.ini with any text editor, you can find
    cp=%CLASSPATH%; in the last line
    add your path of libsvm.jar after ";"

    cp=%CLASSPATH%;D:\Weka3-6\libsvm.jar
    or
    cp=%CLASSPATH%;./libsvm.jar


2014年2月26日 星期三

#define in C is expands textually

#include<stdio.h>
#define square(x) x*x
main() 
{
    int x = 2;
    printf("%d\n", square(x + 1));
    return 0;
}

The answer is 5 not 9, because the preprocessor expands it textually like below.

x * x = 2+1 * 2+1 = 2+(1*2)+1=2+2+1=5
That is not function. We can fix it as

#define square (x) (x)*(x) 
or
#define square (x) ((x)*(x))