mirror of
				https://github.com/esimov/caire.git
				synced 2025-10-31 11:56:19 +08:00 
			
		
		
		
	test: updated test cases
This commit is contained in:
		| @@ -12,12 +12,17 @@ import ( | |||||||
| 	pigo "github.com/esimov/pigo/core" | 	pigo "github.com/esimov/pigo/core" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | const ( | ||||||
|  | 	imgWidth  = 10 | ||||||
|  | 	imgHeight = 10 | ||||||
|  | ) | ||||||
|  |  | ||||||
| var p *Processor | var p *Processor | ||||||
|  |  | ||||||
| func init() { | func init() { | ||||||
| 	p = &Processor{ | 	p = &Processor{ | ||||||
| 		NewWidth:       ImgWidth, | 		NewWidth:       imgWidth, | ||||||
| 		NewHeight:      ImgHeight, | 		NewHeight:      imgHeight, | ||||||
| 		BlurRadius:     1, | 		BlurRadius:     1, | ||||||
| 		SobelThreshold: 4, | 		SobelThreshold: 4, | ||||||
| 		Percentage:     false, | 		Percentage:     false, | ||||||
| @@ -30,11 +35,11 @@ func TestCarver_EnergySeamShouldNotBeDetected(t *testing.T) { | |||||||
| 	var seams [][]Seam | 	var seams [][]Seam | ||||||
| 	var totalEnergySeams int | 	var totalEnergySeams int | ||||||
|  |  | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	dx, dy := img.Bounds().Dx(), img.Bounds().Dy() | 	dx, dy := img.Bounds().Dx(), img.Bounds().Dy() | ||||||
|  |  | ||||||
| 	var c = NewCarver(dx, dy) | 	var c = NewCarver(dx, dy) | ||||||
| 	for x := 0; x < ImgWidth; x++ { | 	for x := 0; x < imgWidth; x++ { | ||||||
| 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
| 		c = NewCarver(width, height) | 		c = NewCarver(width, height) | ||||||
| 		c.ComputeSeams(p, img) | 		c.ComputeSeams(p, img) | ||||||
| @@ -56,7 +61,7 @@ func TestCarver_DetectHorizontalEnergySeam(t *testing.T) { | |||||||
| 	var seams [][]Seam | 	var seams [][]Seam | ||||||
| 	var totalEnergySeams int | 	var totalEnergySeams int | ||||||
|  |  | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	draw.Draw(img, img.Bounds(), &image.Uniform{image.White}, image.Point{}, draw.Src) | 	draw.Draw(img, img.Bounds(), &image.Uniform{image.White}, image.Point{}, draw.Src) | ||||||
|  |  | ||||||
| 	// Replace the pixel colors in a single row from 0xff to 0xdd. 5 is an arbitrary value. | 	// Replace the pixel colors in a single row from 0xff to 0xdd. 5 is an arbitrary value. | ||||||
| @@ -72,7 +77,7 @@ func TestCarver_DetectHorizontalEnergySeam(t *testing.T) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var c = NewCarver(dx, dy) | 	var c = NewCarver(dx, dy) | ||||||
| 	for x := 0; x < ImgWidth; x++ { | 	for x := 0; x < imgWidth; x++ { | ||||||
| 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
| 		c = NewCarver(width, height) | 		c = NewCarver(width, height) | ||||||
| 		c.ComputeSeams(p, img) | 		c.ComputeSeams(p, img) | ||||||
| @@ -94,7 +99,7 @@ func TestCarver_DetectVerticalEnergySeam(t *testing.T) { | |||||||
| 	var seams [][]Seam | 	var seams [][]Seam | ||||||
| 	var totalEnergySeams int | 	var totalEnergySeams int | ||||||
|  |  | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	draw.Draw(img, img.Bounds(), &image.Uniform{image.White}, image.Point{}, draw.Src) | 	draw.Draw(img, img.Bounds(), &image.Uniform{image.White}, image.Point{}, draw.Src) | ||||||
|  |  | ||||||
| 	// Replace the pixel colors in a single column from 0xff to 0xdd. 5 is an arbitrary value. | 	// Replace the pixel colors in a single column from 0xff to 0xdd. 5 is an arbitrary value. | ||||||
| @@ -111,7 +116,7 @@ func TestCarver_DetectVerticalEnergySeam(t *testing.T) { | |||||||
|  |  | ||||||
| 	var c = NewCarver(dx, dy) | 	var c = NewCarver(dx, dy) | ||||||
| 	img = c.RotateImage90(img) | 	img = c.RotateImage90(img) | ||||||
| 	for x := 0; x < ImgHeight; x++ { | 	for x := 0; x < imgHeight; x++ { | ||||||
| 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
| 		c = NewCarver(width, height) | 		c = NewCarver(width, height) | ||||||
| 		c.ComputeSeams(p, img) | 		c.ComputeSeams(p, img) | ||||||
| @@ -130,7 +135,7 @@ func TestCarver_DetectVerticalEnergySeam(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestCarver_RemoveSeam(t *testing.T) { | func TestCarver_RemoveSeam(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	bounds := img.Bounds() | 	bounds := img.Bounds() | ||||||
|  |  | ||||||
| 	// We choose to fill up the background with an uniform white color | 	// We choose to fill up the background with an uniform white color | ||||||
| @@ -169,7 +174,7 @@ func TestCarver_RemoveSeam(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestCarver_AddSeam(t *testing.T) { | func TestCarver_AddSeam(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	bounds := img.Bounds() | 	bounds := img.Bounds() | ||||||
|  |  | ||||||
| 	// We choose to fill up the background with an uniform white color | 	// We choose to fill up the background with an uniform white color | ||||||
| @@ -208,7 +213,7 @@ func TestCarver_AddSeam(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestCarver_ComputeSeams(t *testing.T) { | func TestCarver_ComputeSeams(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
|  |  | ||||||
| 	// We choose to fill up the background with an uniform white color | 	// We choose to fill up the background with an uniform white color | ||||||
| 	// Afterwards we'll replace the colors in a single row with lower intensity ones. | 	// Afterwards we'll replace the colors in a single row with lower intensity ones. | ||||||
| @@ -253,9 +258,8 @@ func TestCarver_ShouldDetectFace(t *testing.T) { | |||||||
| 	dx, dy := img.Bounds().Max.X, img.Bounds().Max.Y | 	dx, dy := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
|  |  | ||||||
| 	c := NewCarver(dx, dy) | 	c := NewCarver(dx, dy) | ||||||
| 	gray := p.Grayscale(img) |  | ||||||
| 	// Transform the image to a pixel array. | 	// Transform the image to a pixel array. | ||||||
| 	pixels := c.rgbToGrayscale(gray) | 	pixels := c.rgbToGrayscale(img) | ||||||
|  |  | ||||||
| 	cParams := pigo.CascadeParams{ | 	cParams := pigo.CascadeParams{ | ||||||
| 		MinSize:     100, | 		MinSize:     100, | ||||||
| @@ -310,7 +314,6 @@ func TestCarver_ShouldNotRemoveFaceZone(t *testing.T) { | |||||||
| 	// Transform the image to a pixel array. | 	// Transform the image to a pixel array. | ||||||
| 	pixels := c.rgbToGrayscale(img) | 	pixels := c.rgbToGrayscale(img) | ||||||
|  |  | ||||||
| 	img = p.Grayscale(img) |  | ||||||
| 	sobel := c.SobelDetector(img, float64(p.SobelThreshold)) | 	sobel := c.SobelDetector(img, float64(p.SobelThreshold)) | ||||||
| 	img = c.StackBlur(sobel, uint32(p.BlurRadius)) | 	img = c.StackBlur(sobel, uint32(p.BlurRadius)) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,13 +6,8 @@ import ( | |||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| const ( |  | ||||||
| 	ImgWidth  = 10 |  | ||||||
| 	ImgHeight = 10 |  | ||||||
| ) |  | ||||||
|  |  | ||||||
| func TestImage_GrayscaleMode(t *testing.T) { | func TestImage_GrayscaleMode(t *testing.T) { | ||||||
| 	img := image.NewRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	for i := 0; i < img.Bounds().Dx(); i++ { | 	for i := 0; i < img.Bounds().Dx(); i++ { | ||||||
| 		for j := 0; j < img.Bounds().Dy(); j++ { | 		for j := 0; j < img.Bounds().Dy(); j++ { | ||||||
| 			img.Set(i, j, color.RGBA{177, 177, 177, 255}) | 			img.Set(i, j, color.RGBA{177, 177, 177, 255}) | ||||||
|   | |||||||
| @@ -6,12 +6,12 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestResize_ShrinkImageWidth(t *testing.T) { | func TestResize_ShrinkImageWidth(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | ||||||
| 	newWidth := ImgWidth / 2 | 	newWidth := imgWidth / 2 | ||||||
|  |  | ||||||
| 	p.NewWidth = newWidth | 	p.NewWidth = newWidth | ||||||
| 	p.NewHeight = ImgHeight | 	p.NewHeight = imgHeight | ||||||
|  |  | ||||||
| 	for x := 0; x < newWidth; x++ { | 	for x := 0; x < newWidth; x++ { | ||||||
| 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
| @@ -28,11 +28,11 @@ func TestResize_ShrinkImageWidth(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestResize_ShrinkImageHeight(t *testing.T) { | func TestResize_ShrinkImageHeight(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | ||||||
| 	newHeight := ImgHeight / 2 | 	newHeight := imgHeight / 2 | ||||||
|  |  | ||||||
| 	p.NewWidth = ImgWidth | 	p.NewWidth = imgWidth | ||||||
| 	p.NewHeight = newHeight | 	p.NewHeight = newHeight | ||||||
|  |  | ||||||
| 	img = c.RotateImage90(img) | 	img = c.RotateImage90(img) | ||||||
| @@ -52,13 +52,13 @@ func TestResize_ShrinkImageHeight(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestResize_EnlargeImageWidth(t *testing.T) { | func TestResize_EnlargeImageWidth(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	origImgWidth := img.Bounds().Dx() | 	origImgWidth := img.Bounds().Dx() | ||||||
| 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | ||||||
| 	newWidth := ImgWidth * 2 | 	newWidth := imgWidth * 2 | ||||||
|  |  | ||||||
| 	p.NewWidth = newWidth | 	p.NewWidth = newWidth | ||||||
| 	p.NewHeight = ImgHeight | 	p.NewHeight = imgHeight | ||||||
|  |  | ||||||
| 	for x := 0; x < newWidth; x++ { | 	for x := 0; x < newWidth; x++ { | ||||||
| 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | 		width, height := img.Bounds().Max.X, img.Bounds().Max.Y | ||||||
| @@ -75,12 +75,12 @@ func TestResize_EnlargeImageWidth(t *testing.T) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func TestResize_EnlargeImageHeight(t *testing.T) { | func TestResize_EnlargeImageHeight(t *testing.T) { | ||||||
| 	img := image.NewNRGBA(image.Rect(0, 0, ImgWidth, ImgHeight)) | 	img := image.NewNRGBA(image.Rect(0, 0, imgWidth, imgHeight)) | ||||||
| 	origImgHeigth := img.Bounds().Dy() | 	origImgHeigth := img.Bounds().Dy() | ||||||
| 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | 	var c = NewCarver(img.Bounds().Dx(), img.Bounds().Dy()) | ||||||
| 	newHeight := ImgHeight * 2 | 	newHeight := imgHeight * 2 | ||||||
|  |  | ||||||
| 	p.NewWidth = ImgWidth | 	p.NewWidth = imgWidth | ||||||
| 	p.NewHeight = newHeight | 	p.NewHeight = newHeight | ||||||
|  |  | ||||||
| 	img = c.RotateImage90(img) | 	img = c.RotateImage90(img) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 esimov
					esimov