Menu

Showing posts with label transformation. Show all posts
Showing posts with label transformation. Show all posts

Thursday, January 21, 2021

[NodeJS - NestJS] ข้อควรระวัง: Class transformer ไม่ตัด properties ส่วนเกินออกจาก Object ปลายทาง
[NodeJS - NestJS] Caution: Class transformer not stripping additional properties

Class transformer เป็นส่วนประกอบนึงของ NestJS ที่ใช้ในการแปลง JSON object ใดๆเป็น class instance ที่เราต้องการ และยังถูกใช้ในการแปลง request ที่ส่งเข้ามาให้เป็น class ที่เราต้องการโดยอัตโนมัติอีกด้วย

สมมติว่า เรามี function ใน controller ดังนี้
@Post()
async createRole (@Body() req: CreateRoleReqDto): Promise <Role> {
    let role = await this.roleService.createRole(req);
    return role;
}
และ class CreateRoleReqDto สำหรับ request ของเราเป็นดังนี้
export class CreateRoleReqDto{
    name: string;
    description?: string;
    permissionIds?: number[];
}
เมื่อเราส่ง request body ดังนี้
{
    "name":"test3",
    "description":"def",    
    "permissionIds": [1,2]
}
request body ของเราจะถูกแปลงเป็น instance ของ CreateRoleReqDto โดยอัตโนมัติ 

Wednesday, October 16, 2013

[EmguCV] การแปลงภาพแบบ Affine
[EmguCV] Affine Transformation

การแปลงภาพแบบ Affine คือ การฉายจุดลงบนฉากรับภาพตามแนวเส้นขนาน นั่นคือ การแปลงภาพที่ยังคงรักษาความขนานของเส้นเอาไว้
Affine transformation is the projection of points onto the image plane along parallel.

ขั้นแรก โหลดภาพตั้งต้นเข้าตัวแปร img
First, load a source image to img 
  1. Image<Bgr, byte> img = new Image<Bgr, byte>(image_path);
Source Image

Wednesday, October 9, 2013

[EmguCV] การแปลงภาพแบบ Perspective
[EmguCV] Perspective Transformation

การแปลงภาพแบบ Perspective คือ การฉายจุดลงบนฉากรับภาพตามแนวเส้นที่พุ่งออกมาจากจุดจุดหนึ่งที่เรียกว่า จุดศูนย์กลางการฉาย
Perspective transformation is the projection of points onto the image plane along lines that emanate from a single point, called the center of projection.

ขั้นแรก โหลดภาพตั้งต้นเข้าตัวแปร img
First, load a source image to img 
  1. Image<Bgr, byte> img = new Image<Bgr, byte>(image_path);
Source image