Hololens V1 – Starting guide

I didn’t touch Hololens for almost 2 years…then I forgot how to use it… It took several days to recall my memory. So I need to write this out otherwise I will forget again.

I have a Hololens with the current OS is 10.0.17763.2114 (Check it at Settings > About), that is Windows 10 Version 1809 (RS5)


https://en.wikipedia.org/wiki/Windows_10_version_history

First I need Visual Studio 2017 and Unity 2018.2.1f1, the same version I used around 2018-2019.

While install Visual Studio Community, ensure that Windows 10 SDK 10.0.17763.0, Universal Windows Platform (UWP), .NET, USB device connection? are selected.

While install Unity, select UWP Build Support (Both IL2CPP and .NET), Vuforia AR Support. Note that Unity 2018.2.1f1 is the last version that can build app with .NET

New Unity 3D project:

1. Main Camera > Clear Flags >
– Change from Skybox to Solid Color,
– Background = Black color.
2. You may change Field of View, Clipping Planes Near-Far later.
3. Add some object to the scene.
– Right click in Hierarchy > 3D Object > Cube.
– Right click in Assets > Create > Material > name = red_material, change albedo color to red.
– Drag the red_material to the cube, then the cube color will become red
Here we finish set up a sample scene.

Unity Setting:

1. Windows > Package Manager > remove Text Mesh Pro package, it will cause a failure build in Visual Studio.
2. Edit > Project Settings > Quality > Select Very Low level. (may not necessary)
3. File > Build Settings >
– Platform = Universal Windows Platform, then click Switch Platform
– Player Settings >
— XR Setting > Select Virtual Reality Support

— Publishing Setting > Capabilities > Select: InternetClient, Webcam, Microphone, SpatialPerception (any stuff you will use in your app)

— Other Setting > Scripting Backend = .NET
(note that I use .NET because I used it since the Unity5.6. Building with the default IL2CPP is failed for my project, though it is the new standard now.)

— Icon > Tiles and Logos > Square 150×150 Logo > Scale 200% (300×300 pixel), Add icon image for your app here! (Scale 100% did not work)

Player Settings >
– Follow settings in the below image.
– Note that don’t select the Enable Mixed Reality Remoting, it will build the app as a 2D window.

Build an app:

Click Build, then create a new folder “app”, the source code will generated in this folder. Otherwise, all the files to deploy to Hololens will messed up in your unity project folder.

It is also easy to just delete the “app” folder to rebuild the app from the scratch. Or create another folder “app2” to build another version of your app.

If build completed, window explorer will pop up showing “app” folder.
Note that the projectname.sln file outside the “app” folder is a project file for unity, we use it when doing coding together with scene design in unity.
To deploy an app to Hololens, you need to open “app/projectname.sln”

<- open this one

Note that you need to turn on developer mode on both pc (Setting > Security) and Hololens.

Connect the Hololens to pc with usb cable.
For the first time of deployment, you will be asked for pairing Hololens with the pc. Go to get the PIN from Hololens (Settings > Updates & Security > For developers > Device discovery > Pair)

Deploying App:

1. Release mode x86
2. Select Device (it will deploy through usb cable)
3. Select “Start without debug” ( Debug > Start without debug). Get the icon by clicking at the small triangle on the right > Customize > Command > Add Command .

Here is the app deployed to the Hololens.

Install CUDA in ubuntu

We can install CUDA library (for using a GPU) by the following command.

sudo apt install nvidia-cuda-toolkit

however it will install the latest release (CUDA 11) which is not supported by many research projects in machine learning yet.

from: https://docs.nvidia.com/deploy/cuda-compatibility/index.html

To install a specific version of CUDA, check the linux driver version using the command “nvidia-smi”, if not satisfy you need to update the linux driver.
Then download CUDA .deb files from
https://developer.nvidia.com/CUDA-TOOLKIT-ARCHIVE

Installation Instructions:
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600

wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda-10-2
sudo apt-get -y install cuda    <- need 1 hr++ to download the upgrade packages needed for installationsudo apt-get -y install cuda-10-2
$ wget http://developer.download.nvidia.com/compute/machinelearning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-
1_amd64.deb
$ sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
$ sudo apt-get update

Then, link the current CUDA version to path environment

#maybe not important to do
export CUDA_HOME=/usr/local/cuda-10.2
export CUDA_ROOT=/usr/local/cuda-10.2
export PATH=$PATH:$CUDA_HOME/bin:$CUDA_HOME/include:$CUDA_HOME
export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH:$CUDA_HOME/include
export CUDA_INC_DIR=$CUDA_INC_DIR:$CUDA_HOME:$CUDA_HOME/include

#sudo dpkg -i cuda-repo-ubuntu1804_10.2.89-1_amd64.deb
sudo dpkg -i libcudnn8_8.0.3.33-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn8-dev_8.0.3.33-1+cuda10.2_amd64.deb
sudo dpkg -i libcudnn8-samples_8.0.3.33-1+cuda10.2_amd64.deb

Download cudnn ( a GPU-accelerated library for deep neuron networks) version that match the CUDA from
https://developer.nvidia.com/rdp/cudnn-archive

Check current version of CUDAcat /usr/local/cuda/version.txt
nvcc –version
Check cudnn versioncat /usr/include/x86_64-linux-gnu/cudnn_v*.h | grep CUDNN_MAJOR -A 2
cat /usr/include/cudnn.h | grep CUDNN_MAJOR -A 2
open bashrc file.gedit .bashrc
reload bashrc, after change it content.source ~/.bashrc
check symbolic link in the folderls -l /usr/local/
create symbolic linkln -s <source_file_directory> <link_file_directory>
print environment variableenv
env | grep -i cuda
rm filename
Useful commands

cat is use for print the detail inside a file.
.bashrc is a file that contains shell configurations and variable of the system.

dpkg is a tool to install, build, remove and manage Debian packages.
-i : install
-p : purge

qt windows deployment

Install Qt Creator 4.11.2
Based on Qt 5.14.2 (MSVC 2017, 32 bit) (64bit?)

ตอนสร้างโปรเจคให้ เลือก qmake ไว้ด้วย

ใน .pro  ใส่ลิงค์ lib ของ opencv

LIBS += C:\opencv3.4.10\build\x64\vc15\lib\opencv_world3410d.lib \
C:\opencv3.4.10\build\x64\vc15\lib\opencv_world3410.lib

ใน project build setting ถ้าเลือก shadow build (เลือกไว้อยู่)  โปรแกรมมันจะไปสร้าง build folder ใหม่ แยกออกจาก project folder

เขียนโค๊ด>run qmake> run build ตามปกติใน qt creator ก็จะได้หน้าต่างโปรแกรม

ข้างในโฟลเดอร์ debug ที่ถูกสร้างขึ้นจากการ build ในตอนแรก

แต่ว่าถ้าเอาโฟลเดอร์นี้ไปเปิดในคอมเครื่องอื่น มันจะขึ้น System error. Qt5Core.dll not found

วิธีแก้

เขียนโฟล์เดอร์ของ qt เพิ่มเข้าไปใน windows environment path

ตอนที่จะสร้างไฟล์สำหรับ deploy

ให้ลบไฟล์อื่นๆ เหลือแค่ โปรแกรมของเรา.exe  แล้วเปิด cmd ในโฟลเดอร์นั้น

พิมพ์ windeployqt.exe –quick .

คำสั่งนี้จะสร้างไฟล์อื่นๆที่เกี่ยวข้องในการรันโปรแกรมมาไว้ในโฟลเดอร์นี้ให้

แต่ว่า .dll ของ opencv ต้อง manual copy จาก C:\opencv3.4.10\build\x64\vc15\bin มาวางไว้ใน build folder เอง

เสร็จแล้วก็ copy ทั้งโฟลเดอร์ไปรันในคอมเครื่องอื่นได้ละ

 

ปล. เจอหนัสือ opencv+qt น่าสนใจ

Computer Vision with OpenCV 3 and Qt5 : build visually appealing, multithreaded, cross-platform computer vision applications

https://github.com/PacktPublishing/Computer-Vision-with-OpenCV-3-and-Qt5

 

Posted in qt

ATR talks note

Robot = special purpose, single task.

Human = tolerant of variability, style matter.

Risk is subjective.

Risk = probability of error * cost of error

Perturbation(การรบกวน) response implements risk-aware reflexion.

Knowing how to respond to the error, make a robot more like a human.

  1. Risk awareness: plan for error
  2. Multiple options: change plan
  3. Flexible behavior : many tasks

ส่งเมลล์ด้วยphp

อัพโหลด ไฟล์ .php ขึ้น server ก็ส่งเมลล์ได้เลย (นึกว่าต้องเช่า server แบบ vps เพื่อส่งเมลล์ผ่าน node.js)

<?php
$to = “—————“;
$subject = “Hello ononon”;
$txt = “test sending email”;
$headers = “From: admin@bumbleplay.com”;   >> ใช้ headers ในการระบุชื่ออีเมลล์ต้นทาง

// Sending email
if(mail($to,$subject,$txt,$headers)){
echo ‘Your mail has been sent successfully.’;
} else{
echo ‘Unable to send email. Please try again.’;
}
?>

Posted in web

Visual studio : Property manager for saving library setting

ปกติจะใช้ opengl / opencv ก็ต้องค่อย add include directories, library directories, add dependancies ทุกครั้งที่สร้างโปรเจคใหม่

แต่ถ้าหากว่า เรามา add library ผ่าน Property Manager แล้ว จะสามารถ save ค่านั้นไว้ ใน Property Sheet

พอสร้างโปรเจคใหม่ ก็แค่ add Property Sheet ไม่กี่คลิ๊ก ช่วยประหยัดเวลาได้เยอะ

วิธีทำ 1. search หา Property Manager จากตรงช่อง Quick Lunch, ก็จะเห็น list project ที่มีอยู่ใน solution ปัจจุบัน

2. กดปุ่ม New Project Property Sheet

3. คลิ๊กขวา ที่ Property Sheet ที่สร้าง > Properties , แล้ว link library ตามปกติ  ค่าที่เซ็ตไว้ก็จะ save อยู่ในไฟล์ Property Sheet

4. กดเลือกโปรเจคที่ยังไม่ได้ link library แล้ว กดปุ่ม Add Existing Property Sheet, แล้วก็เลือกไฟล์  Property Sheet

5. ก็จะเห็นว่า ที่ Projectที่สอง มี Property Sheet ที่ถูกเซ็ตเอาไว้ใน Project ก่อนหน้า

ลองกด Properties ดู ก็มี link library อยู่ครบ

import csv file to excel with utf8

.csv file ของ questionnaire data ที่ download มาจาก google forms ถ้าเปิดใน excel ตรงๆ ภาษาที่ไม่ใช่ภาษาอังกฤษจะเพี้ยน

 

แก้ โดย เปิด excel new file ขึ้นมา แล้ว import data เอา จะสามารถเลือก ภาษาเป็น utf8ได้

 

 

 

python opencv

พอดีว่าจะลอง tutorial  Simple Background Estimation in Videos using OpenCV (C++/Python)

ลองรันโค๊ดpython  จำได้เคยinstall python anoconda อยู่

ลองเสิร์จหาดู ไปอยู่ในโฟลเดอร์ C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64

ก็เอา โฟลเดอร์นี้ไป add ใน environment path จะได้เรียก python ผ่าน command line ได้

run  cmd as administrator จะได้ install library ได้

python -m pip install numpy

python -m pip install opencv-python

python -m pip install scikit-image

python -m pip install scipy

cd  C:\learnopencv-master\VideoBackgroundEstimation

python removeVideoBg.py รันโปรแกรม

เป็นโปรแกรมตัด background ของวีดีโอ โดยที่มุมกล้องไม่ขยับ

ตอนแรกโปรแกรมก็จะคำนวณ background ของ video โดยหาค่า median  แล้วก็โชว์ภาพbgที่คำนวณได้

พอเราปิดหน้าต่างรูป bg  โปรแกรมจะโชว์วีดีโอที่ตัด bg ออกแล้ว

 

c++ build

 

เปิด cmakeแล้วก็ ระบุ source กับ build folder

ที่เหลือ โปรแกรมจะเรียกอ่านไฟล์ CMakeLists.txt เอง

แต่ว่าเราต้องกำหนด path openCV ไว้ใน environment ก่อน

ถ้าไม่ใส่ bin folder  ตอนรัน visualstudio มันจะ error หา dll ไม่เจอ

ถ้าไม่ใส่ build folder,  ถึงแม้เราจะกำหนดเอง cmake จะหา build folder ของ opencv ไม่เจอ

 

 

 

 

 

 

แต่ว่าโปรเจค c++ รันแล้วไป error ตรงเปิดวีดีโอแฮะ

คือว่า วีดีโอกับ ตัวโปรแกรมไม่ได้อยู่โฟสเดอร์เดียวกันละ

เลยต้องมาเซ็ต command argument ให้ visualstudio อ่าน video pathที่กำหนดไว้