Ref: https://websiteforstudents.com/connect-to-ubuntu-16-04-17-10-18-04-desktop-via-remote-desktop-connection-rdp-with-xrdp/
1. Ubuntu desktop Install Xrdp Server
sudo apt install xrdp
sudo systemctl enable xrdp
2.
3. (取消查核)
4. 注意不可同時以相同帳號登入,遠端使用者須先自Ubuntu Desktop中登出,否則Remote desktop 會閃退。
2019年2月17日 星期日
2019年1月11日 星期五
2019年1月7日 星期一
更改 Google Form 樣式
Ref: https://www.brandeis.edu/communications/digital/toolkit/google-forms.html
1. Google Form template 選用
Google Form template 可以透過變更帳戶語言(English)方式,選用內建範本。
2. Google Form 字型變更,可以透過選取舊版本(click 右下角問號),進行編輯。
1. Google Form template 選用
Google Form template 可以透過變更帳戶語言(English)方式,選用內建範本。
2. Google Form 字型變更,可以透過選取舊版本(click 右下角問號),進行編輯。
2018年12月27日 星期四
WebAR 測試
Ref: https://aframe.io/blog/arjs/
asp.net core sdk 2.1 @ windows 10 x64
1. dotnet new web -o wk15b
2. Program.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace wk15b
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://192.168.1.108:5000/","https://192.168.1.108:5001/")
.UseStartup<Startup>();
}
}
3. Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace wk15b
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); // Add
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc();
}
}
}
asp.net core sdk 2.1 @ windows 10 x64
1. dotnet new web -o wk15b
2. Program.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace wk15b
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://192.168.1.108:5000/","https://192.168.1.108:5001/")
.UseStartup<Startup>();
}
}
3. Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace wk15b
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(); // Add
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
app.UseMvc();
}
}
}
4. wk1502.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<script src="https://jeromeetienne.github.io/AR.js/aframe/build/aframe-ar.js"></script>
</head>
<body style='margin : 0px; overflow: hidden;'>
<a-scene embedded arjs='sourceType: webcam;'>
<!-- handle marker with hiro preset -->
<a-marker preset='hiro'>
<a-box position='0 2 -1' material='color: green;'></a-box>
</a-marker>
</a-scene>
</body>
</html>
5. Results
2018年12月25日 星期二
ML.NET Taxi Fare Prediction 測試
Ref: https://github.com/dotnet/machinelearning-samples/tree/master/samples/csharp/getting-started/Regression_TaxiFarePrediction
Visual Studio 2017 @ Windows 10 x64
1. New console project
2. nuget add ML.NET 0.8.0
3. nuget add PLplot
4. 合併成同一檔案:
5下載 資料檔案到 上一層 Data 目錄
taxi-fare-test.csv
taxi-fare-train.csv
6. 上一層建置MLModels
7. Result
Visual Studio 2017 @ Windows 10 x64
1. New console project
2. nuget add ML.NET 0.8.0
3. nuget add PLplot
4. 合併成同一檔案:
5下載 資料檔案到 上一層 Data 目錄
taxi-fare-test.csv
taxi-fare-train.csv
6. 上一層建置MLModels
7. Result
2018年12月19日 星期三
ML.NET by Desktop Console
1, 參考 ML.NET 案例,採用SDK Core Console App. 改為Desktop App
2. Errors
2-1 AnyCPU ==> x64 or x86 Sel x64
2-2 建置/進階 ==> C#7.1
2018年12月11日 星期二
Emgu FacialMouseControl by Kinect CAM
Ref: https://github.com/emgucv/emgucv/tree/master/Emgu.CV.Example/FacialMouseControl
Windows 10 x64 @ ASUS X450J + Visual Studio 2017 + Emgu 3.2.0.2721 + Kinect 1.8 SDK
1. MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wk1302
{
// 1. nuget emgu 3.4.3
// 2. Add using ref FaceMouse
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Interop;
//-- Kinect cam
using Microsoft.Kinect;
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
private VideoCapture _capture;
// https://stackoverflow.com/questions/46410342/c-sharp-emgu-could-not-be-found-capture-and-haarcascade
//private HaarCascade _face;
private CascadeClassifier _face;
private KinectSensor sensor;
/// <summary>
/// Bitmap that will hold color information
/// </summary>
private WriteableBitmap colorBitmap;
/// <summary>
/// Intermediate storage for the color data received from the camera
/// </summary>
private byte[] colorPixels;
public MainWindow()
{
InitializeComponent();
_face = new CascadeClassifier("haarcascade_frontalface_alt2.xml");
sensor = KinectSensor.KinectSensors[0];
this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
// Allocate space to put the pixels we'll receive
this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
// This is the bitmap we'll display on-screen
this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
// Set the image we display to point to the bitmap where we'll put the image data
this.image1.Source = this.colorBitmap;
// Add an event handler to be called whenever there is new color frame data
this.sensor.ColorFrameReady += this.SensorColorFrameReady;
// Start the sensor!
this.sensor.Start();
// https://stackoverflow.com/questions/1111615/getting-inactivity-idle-time-in-a-wpf-application
ComponentDispatcher.ThreadIdle += ComponentDispatcher_ThreadIdle;
}
private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * sizeof(int),
0);
}
}
}
int count = 0;
private void ComponentDispatcher_ThreadIdle(object sender, EventArgs e)
{
this.Title = (count++).ToString();
using (var imageFrame = (BitmapSourceConvert.ToMat(colorBitmap)).ToImage<Bgr, byte>())
{
if (imageFrame != null)
{
var grayframe = imageFrame.Convert<Gray, byte>();
var vfaces = _face.DetectMultiScale(grayframe, 1.1, 10, System.Drawing.Size.Empty); //the actual face detection happens here
if (vfaces.Length > 0)
{
System.Drawing.Rectangle Maxface = vfaces[0];
int maxw = vfaces[0].Width;
int maxh = vfaces[0].Height;
for (int i = 1; i < vfaces.Length; i++)
{
if (vfaces[i].Width * vfaces[i].Height > maxw * maxh)
{
Maxface = vfaces[i];
maxw = vfaces[i].Width;
maxh = vfaces[i].Height;
}
}
imageFrame.Draw(Maxface, new Bgr(System.Drawing.Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them
//---
System.Drawing.Point biggestFaceCenter = new System.Drawing.Point(Maxface.X + Maxface.Width / 2, Maxface.Y + Maxface.Height / 2);
//Point imageAreaCenter = new Point(imageArea.X + imageArea.Width / 2, imageArea.Y + imageArea.Height / 2);
//draw a green cross at the center of the biggest face
imageFrame.Draw(
new Cross2DF(biggestFaceCenter, Maxface.Width * 0.1f, Maxface.Height * 0.1f),
new Bgr(0, 255, 0), 1);
}
}
image1.Source = BitmapSourceConvert.ToBitmapSource(imageFrame);
}
}
// Add ref: SYstem.Drawing.DLL
public static class BitmapSourceConvert
{
[DllImport("gdi32")]
private static extern int DeleteObject(IntPtr o);
public static BitmapSource ToBitmapSource(IImage image)
{
using (System.Drawing.Bitmap source = image.Bitmap)
{
IntPtr ptr = source.GetHbitmap();
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ptr,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ptr);
return bs;
}
}
//ref: https://stackoverflow.com/questions/16596915/emgu-with-c-sharp-wpf/16597958
public static Mat ToMat(BitmapSource source)
{
if (source.Format == PixelFormats.Bgr32) // .Bgra32)
{
Mat result = new Mat();
result.Create(source.PixelHeight, source.PixelWidth, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
source.CopyPixels(Int32Rect.Empty, result.DataPointer, result.Step * result.Rows, result.Step);
return result;
}
else if (source.Format == PixelFormats.Bgr24)
{
Mat result = new Mat();
result.Create(source.PixelHeight, source.PixelWidth, Emgu.CV.CvEnum.DepthType.Cv8U, 3);
source.CopyPixels(Int32Rect.Empty, result.DataPointer, result.Step * result.Rows, result.Step);
return result;
}
else
{
throw new Exception(String.Format("Convertion from BitmapSource of format {0} is not supported.", source.Format));
}
}
}
}
}
Windows 10 x64 @ ASUS X450J + Visual Studio 2017 + Emgu 3.2.0.2721 + Kinect 1.8 SDK
1. MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wk1302
{
// 1. nuget emgu 3.4.3
// 2. Add using ref FaceMouse
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using System.Threading;
using System.Runtime.InteropServices;
using System.Windows.Interop;
//-- Kinect cam
using Microsoft.Kinect;
/// <summary>
/// MainWindow.xaml 的互動邏輯
/// </summary>
public partial class MainWindow : Window
{
private VideoCapture _capture;
// https://stackoverflow.com/questions/46410342/c-sharp-emgu-could-not-be-found-capture-and-haarcascade
//private HaarCascade _face;
private CascadeClassifier _face;
private KinectSensor sensor;
/// <summary>
/// Bitmap that will hold color information
/// </summary>
private WriteableBitmap colorBitmap;
/// <summary>
/// Intermediate storage for the color data received from the camera
/// </summary>
private byte[] colorPixels;
public MainWindow()
{
InitializeComponent();
_face = new CascadeClassifier("haarcascade_frontalface_alt2.xml");
sensor = KinectSensor.KinectSensors[0];
this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
// Allocate space to put the pixels we'll receive
this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength];
// This is the bitmap we'll display on-screen
this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null);
// Set the image we display to point to the bitmap where we'll put the image data
this.image1.Source = this.colorBitmap;
// Add an event handler to be called whenever there is new color frame data
this.sensor.ColorFrameReady += this.SensorColorFrameReady;
// Start the sensor!
this.sensor.Start();
// https://stackoverflow.com/questions/1111615/getting-inactivity-idle-time-in-a-wpf-application
ComponentDispatcher.ThreadIdle += ComponentDispatcher_ThreadIdle;
}
private void SensorColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
// Copy the pixel data from the image to a temporary array
colorFrame.CopyPixelDataTo(this.colorPixels);
// Write the pixel data into our bitmap
this.colorBitmap.WritePixels(
new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
this.colorPixels,
this.colorBitmap.PixelWidth * sizeof(int),
0);
}
}
}
int count = 0;
private void ComponentDispatcher_ThreadIdle(object sender, EventArgs e)
{
this.Title = (count++).ToString();
using (var imageFrame = (BitmapSourceConvert.ToMat(colorBitmap)).ToImage<Bgr, byte>())
{
if (imageFrame != null)
{
var grayframe = imageFrame.Convert<Gray, byte>();
var vfaces = _face.DetectMultiScale(grayframe, 1.1, 10, System.Drawing.Size.Empty); //the actual face detection happens here
if (vfaces.Length > 0)
{
System.Drawing.Rectangle Maxface = vfaces[0];
int maxw = vfaces[0].Width;
int maxh = vfaces[0].Height;
for (int i = 1; i < vfaces.Length; i++)
{
if (vfaces[i].Width * vfaces[i].Height > maxw * maxh)
{
Maxface = vfaces[i];
maxw = vfaces[i].Width;
maxh = vfaces[i].Height;
}
}
imageFrame.Draw(Maxface, new Bgr(System.Drawing.Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them
//---
System.Drawing.Point biggestFaceCenter = new System.Drawing.Point(Maxface.X + Maxface.Width / 2, Maxface.Y + Maxface.Height / 2);
//Point imageAreaCenter = new Point(imageArea.X + imageArea.Width / 2, imageArea.Y + imageArea.Height / 2);
//draw a green cross at the center of the biggest face
imageFrame.Draw(
new Cross2DF(biggestFaceCenter, Maxface.Width * 0.1f, Maxface.Height * 0.1f),
new Bgr(0, 255, 0), 1);
}
}
image1.Source = BitmapSourceConvert.ToBitmapSource(imageFrame);
}
}
// Add ref: SYstem.Drawing.DLL
public static class BitmapSourceConvert
{
[DllImport("gdi32")]
private static extern int DeleteObject(IntPtr o);
public static BitmapSource ToBitmapSource(IImage image)
{
using (System.Drawing.Bitmap source = image.Bitmap)
{
IntPtr ptr = source.GetHbitmap();
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ptr,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ptr);
return bs;
}
}
//ref: https://stackoverflow.com/questions/16596915/emgu-with-c-sharp-wpf/16597958
public static Mat ToMat(BitmapSource source)
{
if (source.Format == PixelFormats.Bgr32) // .Bgra32)
{
Mat result = new Mat();
result.Create(source.PixelHeight, source.PixelWidth, Emgu.CV.CvEnum.DepthType.Cv8U, 4);
source.CopyPixels(Int32Rect.Empty, result.DataPointer, result.Step * result.Rows, result.Step);
return result;
}
else if (source.Format == PixelFormats.Bgr24)
{
Mat result = new Mat();
result.Create(source.PixelHeight, source.PixelWidth, Emgu.CV.CvEnum.DepthType.Cv8U, 3);
source.CopyPixels(Int32Rect.Empty, result.DataPointer, result.Step * result.Rows, result.Step);
return result;
}
else
{
throw new Exception(String.Format("Convertion from BitmapSource of format {0} is not supported.", source.Format));
}
}
}
}
}
2. Result:
訂閱:
文章 (Atom)









