Water's Home

Just another Life Style

0%

Slider

createTrackbar(“Lena”, “Lena”, &blurAmount, 30, onChange, &lena);

onChange(blurAmount, &lena);

static void onChange(int pos, void* userInput)
{
if(pos <= 0)
return;
// Aux variable for result
Mat imgBlur;

// Get the pointer input image
Mat* img= (Mat*)userInput;

// Apply a blur filter
blur(*img, imgBlur, Size(pos, pos));

// Show the result
imshow(“Lena”, imgBlur);
}

Mouse

setMouseCallback(“Lena”, onMouse, &lena);

static void onMouse( int event, int x, int y, int, void* userInput )
{
if( event != EVENT_LBUTTONDOWN )
return;

// Get the pointer input image
Mat* img= (Mat*)userInput;

// Draw circle
circle(*img, Point(x, y), 10, Scalar(0,255,0), 3);

// Call on change to get blurred image
onChange(blurAmount, img);

}

Button(QT_CHECKBOX, QT_RADIOBOX, QT_PUSH_BUTTON)

void grayCallback(int state, void* userData)
{
applyGray= true;
applyFilters();
}
void bgrCallback(int state, void* userData)
{
applyGray= false;
applyFilters();
}

void blurCallback(int state, void* userData)
{
applyBlur= (bool)state;
applyFilters();
}

void sobelCallback(int state, void* userData)
{
applySobel= !applySobel;
applyFilters();
}

createButton(“Blur”, blurCallback, NULL, QT_CHECKBOX, 0);

createButton(“Gray”,grayCallback,NULL,QT_RADIOBOX, 0);
createButton(“RGB”,bgrCallback,NULL,QT_RADIOBOX, 1);

createButton(“Sobel”,sobelCallback,NULL,QT_PUSH_BUTTON, 0);

Simple Window

namedWindow(“Photo”, WINDOW_AUTOSIZE);

moveWindow(“Photo”, 520, 10);

imshow(“Photo”, photo);

resizeWindow(“Lena”, 512, 512);

destroyWindow(“Photo”);

destroyAllWindows();//

Qt Functions

displayOverlay(“Lena”, “Overlay 5secs”, 5000);

displayStatusBar(“Lena”, “Status bar 5secs”, 5000);

saveWindowParameters(“Lena”);

loadWindowParameters(“Lena”);

Write OpenCV Data

FileStorage fs(“test.yml”, FileStorage::WRITE);
Mat m1= Mat::eye(2,3, CV_32F);
fs << “m1” << m1;
fs.release();

Read OpenCV Data

FileStorage fs2(“test.yml”, FileStorage::READ);
Mat r;
fs2[“m1”] >> r;
std::cout << r << std::endl;
fs2.release();

Read Image

Mat color= imread(“../lena.jpg”);
Mat gray= imread(“../lena.jpg”, 0);

Write Image

imwrite(“lenaGray.jpg”, gray);

Show Image

imshow(“Lena Gray”, gray);

Read VideoFile/Camera

VideoCapture cap;
cap.open(videoFile);
cap.open(0);//default camera

if(!cap.isOpened()) // check if succeeded
return -1;

cap.release();

Show VideoFile/Camera

namedWindow(“Video”,1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow(“Video”, frame);
if(waitKey(30) >= 0) break;
}

Install VTK

water@waters-MacBook-Pro:/Downloads/VTK-8.1.0/build$ cmake ..
water@waters-MacBook-Pro:
/Downloads/VTK-8.1.0/build$ make
water@waters-MacBook-Pro:~/Downloads/VTK-8.1.0/build$ sudo make install

Install QT5

water@waters-MacBook-Pro:/Documents/GitHub/opencv/build$ brew install qt5
water@waters-MacBook-Pro:
/Documents/GitHub/opencv/build$ export “PATH=/usr/local/opt/qt/bin:$PATH”

Install OpenCV & OpenCV_contrib

water@waters-MacBook-Pro:~/Documents/GitHub/opencv/build$ cmake -DCMAKE_BUILD_TYPE=Release -DWITH_OPENGL=ON -DWITH_OPENVX=ON -DWITH_QT=ON -DWITH_OPENCL=ON -DOPENCV_EXTRA_MODULES_PATH=/Users/water/Documents/GitHub/opencv_contrib/modules –DWITH_VTK=ON -DVTK_DIR=/Users/water/Downloads/VTK-8.1.0 ..

water@waters-MacBook-Pro:/Documents/GitHub/opencv/build$ make -j8
water@waters-MacBook-Pro:
/Documents/GitHub/opencv/build$ sudo make install

Test VIZ

#include #include #include using namespace cv;
using namespace std;

/*
* @function main
*/
int main()
{
/// Create a window
viz::Viz3d myWindow(“Coordinate Frame”);

/// Add coordinate axes
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());

/// Add line to represent (1,1,1) axis
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
axis.setRenderingProperty(viz::LINE\_WIDTH, 4.0);
myWindow.showWidget("Line Widget", axis);

/// Construct a cube widget
viz::WCube cube\_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
cube\_widget.setRenderingProperty(viz::LINE\_WIDTH, 4.0);

/// Display widget (update if already displayed)
myWindow.showWidget("Cube Widget", cube\_widget);

/// Rodrigues vector
Mat rot\_vec = Mat::zeros(1,3,CV\_32F);
float translation\_phase = 0.0, translation = 0.0;
while(!myWindow.wasStopped())
{
    /\* Rotation using rodrigues \*/
    /// Rotate around (1,1,1)
    rot\_vec.at(0,0) += CV\_PI \* 0.01f;
    rot\_vec.at(0,1) += CV\_PI \* 0.01f;
    rot\_vec.at(0,2) += CV\_PI \* 0.01f;

    /// Shift on (1,1,1)
    translation\_phase += CV\_PI \* 0.01f;
    translation = sin(translation\_phase);

    Mat rot\_mat;
    Rodrigues(rot\_vec, rot\_mat);

    /// Construct pose
    Affine3f pose(rot\_mat, Vec3f(translation, translation, translation));

    myWindow.setWidgetPose("Cube Widget", pose);

    myWindow.spinOnce(1, true);
}

return 0;

}

Test OpenGL

#include #include #include using namespace std;

// OpenGL includes
#ifdef __APPLE__
#include #else
#include #endif

// OpenCV includes
#include “opencv2/core.hpp”
#include “opencv2/imgproc.hpp”
#include “opencv2/highgui.hpp”
using namespace cv;

Mat frame;
GLfloat angle= 0.0;
GLuint texture;
VideoCapture camera;

int loadTexture() {

if (frame.data==NULL) return -1;

glBindTexture( GL\_TEXTURE\_2D, texture ); //bind the texture to it's array
glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MAG\_FILTER,GL\_LINEAR);
glTexParameteri(GL\_TEXTURE\_2D,GL\_TEXTURE\_MIN\_FILTER,GL\_LINEAR);

glPixelStorei(GL\_UNPACK\_ALIGNMENT, 1);

glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, frame.cols, frame.rows,0, GL\_BGR, GL\_UNSIGNED\_BYTE, frame.data);
return 0;

}

void on_opengl(void* param)
{
glLoadIdentity();
// Load Texture
glBindTexture( GL_TEXTURE_2D, texture );
// Rotate plane
glRotatef( angle, 1.0f, 1.0f, 1.0f );
// Create the plate
glBegin (GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();

}

int main( int argc, const char** argv )
{
// Open WebCam
camera.open(0);
if(!camera.isOpened())
return -1;

// Create new windows
namedWindow("OpenGL Camera", WINDOW\_OPENGL);

// Enable texture
glEnable( GL\_TEXTURE\_2D );
glGenTextures(1, &texture);

setOpenGlDrawCallback("OpenGL Camera", on\_opengl);

while(waitKey(30)!='q'){
    camera >> frame;
    // Create first texture
    loadTexture();
    updateWindow("OpenGL Camera");
    angle =angle+4;
}

// Destroy the windows
destroyWindow(“OpenGL Camera”);

return 0;
}

Install tesseract

water@waters-MBP:~$ brew install tesseract –with-all-languages

Have a test

water@waters-MBP:~/Downloads$ tesseract tesseract-test-english.png out

Install chi-sim.traineddata

water@waters-MBP:~$ ls -al /usr/local/Cellar/tesseract/3.05.01/share/tessdata/chi-sim.traineddata
-rw-r–r– 1 water admin 52662579 Jan 20 22:30 /usr/local/Cellar/tesseract/3.05.01/share/tessdata/chi-sim.traineddata

Have a test

water@waters-MBP:~/Downloads$ tesseract tesseract-test-chinese.png out -l chi-sim

Configure Firewall

systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd –state

sed -i ‘/^SELINUX=.*/c SELINUX=disabled’ /etc/selinux/config
sed -i ‘s/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g’ /etc/selinux/config
grep –color=auto ‘^SELINUX’ /etc/selinux/config
setenforce 0

Install KVM & Virt

yum install qemu-kvm libvirt -y
yum install virt-install -y

Start Virt Service

systemctl start libvirtd && systemctl enable libvirtd

[root@localhost ~]# ifconfig
ens33: flags=4163 mtu 1500
inet 192.168.220.202 netmask 255.255.255.0 broadcast 192.168.220.255
inet6 fe80::c269:7c04:a06b:dce7 prefixlen 64 scopeid 0x20
ether 00:0c:29:4e:32:2a txqueuelen 1000 (Ethernet)
RX packets 3394211 bytes 4731781088 (4.4 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 264816 bytes 35363147 (33.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback)
RX packets 68 bytes 5920 (5.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 68 bytes 5920 (5.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a5:ea:48 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Create Disk

[root@localhost ~]# qemu-img create -f raw /opt/CentOS-7-x86_64.raw 10G
Formatting ‘/opt/CentOS-7-x86_64.raw’, fmt=raw size=10737418240

Upload System ISO

[root@localhost ~]# ls /ISO
CentOS-7-x86_64-DVD-1708.iso

Begin Install OS

[root@localhost ~]# virt-install –virt-type kvm –name CentOS-7-x86_64 –ram 1024 –cdrom=/ISO/CentOS-7-x86_64-DVD-1708.iso –disk path=/opt/CentOS-7-x86_64.raw –network network=default –graphics vnc,listen=0.0.0.0 –noautoconsole

Starting install…
Domain installation still in progress. You can reconnect to
the console to complete the installation process.

Connect With VNC

List Virtual Machine

[root@localhost ~]# virsh list –all
Id Name State


  • CentOS-7-x86\_64                shut off
    

Start Virtual Machine

[root@localhost ~]# virsh start CentOS-7-x86_64
Domain CentOS-7-x86_64 started

[root@localhost ~]# virsh list –all
Id Name State


3 CentOS-7-x86_64 running

Test Virtual Machine

List Virbr

[root@localhost ~]# brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.525400a5ea48 yes virbr0-nic
vnet0

List br0 Status

[root@localhost ~]# vi create-br0.sh

[root@localhost ~]# cat create-br0.sh
brctl addbr br0
brctl addif br0 ens33
ip addr del dev ens33 192.168.220.202/24
ifconfig br0 192.168.220.202/24 up
route add default gw 192.168.220.2

[root@localhost ~]# chmod +x create-br0.sh
[root@localhost ~]# ./create-br0.sh

Create br0

[root@localhost network-scripts]# ifconfig
br0: flags=4163 mtu 1500
inet 192.168.220.202 netmask 255.255.255.0 broadcast 192.168.220.255
inet6 fe80::20c:29ff:fe4e:322a prefixlen 64 scopeid 0x20
ether 00:0c:29:4e:32:2a txqueuelen 1000 (Ethernet)
RX packets 144 bytes 12890 (12.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 17020 (16.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ens33: flags=4163 mtu 1500
inet6 fe80::c269:7c04:a06b:dce7 prefixlen 64 scopeid 0x20
ether 00:0c:29:4e:32:2a txqueuelen 1000 (Ethernet)
RX packets 3432987 bytes 4745607852 (4.4 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 297978 bytes 44267836 (42.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback)
RX packets 68 bytes 5920 (5.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 68 bytes 5920 (5.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4163 mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:a5:ea:48 txqueuelen 1000 (Ethernet)
RX packets 3970 bytes 167470 (163.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4261 bytes 11695250 (11.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vnet0: flags=4163 mtu 1500
inet6 fe80::fc54:ff:feaf:a499 prefixlen 64 scopeid 0x20
ether fe:54:00:af:a4:99 txqueuelen 1000 (Ethernet)
RX packets 3970 bytes 223050 (217.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5218 bytes 11745246 (11.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Vir Edit to Bridge Network

[root@localhost ~]# virsh edit CentOS-7-x86_64
Domain CentOS-7-x86_64 XML configuration edited.

Before Edit

After Edit

Restart Virtual Machine

[root@localhost ~]# virsh shutdown CentOS-7-x86_64
Domain CentOS-7-x86_64 is being shutdown

[root@localhost ~]# virsh start CentOS-7-x86_64
Domain CentOS-7-x86_64 started

Look at the Virtual Machine IP

Install Golang 1.4

tar -C /usr/local -xzf go1.4.3.linux-amd64.tar.gz
mkdir $HOME/go
echo ‘export GOROOT=/usr/local/go’>> ~/.bashrc
echo ‘export GOPATH=$HOME/go’>> ~/.bashrc
echo ‘export PATH=$PATH:$GOROOT/bin’>> ~/.bashrc
source /root/.bashrc

Install Git

yum install mercurial git bzr subversion -y

Install Ngrok

cd /usr/local/src/
git clone https://github.com/inconshreveable/ngrok.git

Generate CERT

export NGROK_DOMAIN=”www.qinuu.com"

cd ngrok/
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -subj “/CN=$NGROK_DOMAIN” -days 5000 -out rootCA.pem
openssl genrsa -out device.key 2048
openssl req -new -key device.key -subj “/CN=$NGROK_DOMAIN” -out device.csr
openssl x509 -req -in device.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out device.crt -days 5000

cp rootCA.pem assets/client/tls/ngrokroot.crt
cp device.crt assets/server/tls/snakeoil.crt
cp device.key assets/server/tls/snakeoil.key

Make Linux Server

GOOS=linux GOARCH=amd64
make release-server release-client

Make Windows Client

cd /usr/local/go/src
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 ./make.bash
cd /usr/local/src/ngrok/
GOOS=windows GOARCH=amd64 make release-server release-client

Start Ngrok Service

nohup bin/ngrokd -domain=”www.qinuu.com" -httpAddr=”:8080” -httpsAddr=”:8443” &

Download Windows Client

ls -al bin/windows_amd64/

Configure CLient CFG File

Start Windows Client