How to use putText method of main Package

Best Syzkaller code snippet using main.putText

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "fmt"4 "image"5 "image/color"6 "github.com/Danile71/go-face"7 "github.com/Danile71/go-logger"8 "gocv.io/x/gocv"9)10const (11 cnnModel = "models/mmod_human_face_detector.dat"12 shapeModel = "models/shape_predictor_68_face_landmarks.dat" // "models/shape_predictor_5_face_landmarks.dat"13 descrModel = "models/dlib_face_recognition_resnet_model_v1.dat"14 ageModel = "models/dnn_age_predictor_v1.dat"15 genderModel = "models/dnn_gender_classifier_v1.dat"16 faceImage = "images/face.jpg"17 facesImage = "images/faces.jpg"18)19var (20 greenColor = color.RGBA{0, 255, 0, 255}21 redColor = color.RGBA{255, 0, 0, 255}22)23func init() {24 logger.SetLevel(logger.DEBUG)25}26func main() {27 // try to find him28 var descriptor face.Descriptor29 // craete window30 w := gocv.NewWindow("example")31 defer w.Close()32 // Init recognizer33 rec, err := face.NewRecognizer()34 if logger.OnError(err) {35 return36 }37 // close it38 defer rec.Close()39 // Load shape model40 if err = rec.SetShapeModel(shapeModel); logger.OnError(err) {41 return42 }43 // Load description model44 if err = rec.SetDescriptorModel(descrModel); logger.OnError(err) {45 return46 }47 // Load age model48 if err = rec.SetAgeModel(ageModel); logger.OnError(err) {49 return50 }51 // Load gener model52 if err = rec.SetGenderModel(genderModel); logger.OnError(err) {53 return54 }55 // Load CNN model56 if err = rec.SetCNNModel(cnnModel); logger.OnError(err) {57 return58 }59 // load first image60 img1 := gocv.IMRead(faceImage, gocv.IMReadUnchanged)61 defer img1.Close()62 // load second image63 img2 := gocv.IMRead(facesImage, gocv.IMReadUnchanged)64 defer img2.Close()65 // copy bg to draw66 background := img2.Clone()67 defer background.Close()68 // try detect faces69 faces, err := rec.DetectFromMatCNN(img1)70 if logger.OnError(err) {71 return72 }73 for _, f := range faces {74 defer f.Close()75 // get face description76 if err = rec.Recognize(&f); err != nil {77 return78 }79 // predict face age80 rec.GetAge(&f)81 // predict face gender82 rec.GetGender(&f)83 // set descriptor84 descriptor = f.Descriptor85 // draw rect86 gocv.Rectangle(&img1, f.Rectangle, greenColor, 2)87 gocv.PutText(&img1, fmt.Sprintf("%s:%d y.o.", f.Gender, f.Age), image.Point{f.Rectangle.Min.X - 20, f.Rectangle.Min.Y - 5}, gocv.FontHersheyPlain, 1, redColor, 1)88 }89 gocv.PutText(&img1, "press any key...", image.Point{0, img1.Cols() - 30}, gocv.FontHersheyPlain, 1, redColor, 1)90 w.IMShow(img1)91 fmt.Println("press any key to continue...")92 for {93 if key := w.WaitKey(1000); key != -1 {94 break95 }96 }97 faces, err = rec.DetectFromMatCNN(img2)98 if logger.OnError(err) {99 return100 }101 for _, f := range faces {102 defer f.Close()103 if err = rec.Recognize(&f); err != nil {104 return105 }106 rec.GetAge(&f)107 rec.GetGender(&f)108 gocv.Rectangle(&background, f.Rectangle, greenColor, 2)109 gocv.PutText(&background, fmt.Sprintf("%s:%d y.o.", f.Gender, f.Age), image.Point{f.Rectangle.Min.X - 20, f.Rectangle.Min.Y - 5}, gocv.FontHersheyPlain, 1, redColor, 1)110 dist := face.SquaredEuclideanDistance(f.Descriptor, descriptor)111 c := redColor112 if dist < 0.1 {113 c = greenColor114 }115 gocv.PutText(&background, fmt.Sprintf("%f", dist), image.Point{f.Rectangle.Min.X, f.Rectangle.Max.Y}, gocv.FontHersheyPlain, 1, c, 1)116 }117 w.IMShow(background)118 fmt.Println("press any key to exit...")119 for {120 if key := w.WaitKey(1000); key != -1 {121 return122 }123 }124}...

Full Screen

Full Screen

message.go

Source:message.go Github

copy

Full Screen

1package main23import (4 "encoding/json"5 "image"6 "image/color"7 "log"8 "goconsumer/models"9 "strings"1011 "github.com/confluentinc/confluent-kafka-go/kafka"12 "gocv.io/x/gocv"13)1415var statusColor = color.RGBA{200, 150, 50, 0}16var bkgColor = color.RGBA{255, 255, 255, 0}17var boxColor = color.RGBA{0, 0, 255, 0}1819func message(ev *kafka.Message) error {2021 //Read message into `topicMsg` struct22 doc := &topicMsg{}23 err := json.Unmarshal(ev.Value, doc)24 if err != nil {25 log.Println(err)26 return err27 }2829 // Retrieve frame30 log.Printf("%% Message sent %v on %s\n", ev.Timestamp, ev.TopicPartition)31 frame, err := gocv.NewMatFromBytes(doc.Rows, doc.Cols, doc.Type, doc.Mat)32 if err != nil {33 log.Println("Frame:", err)34 return err35 }3637 // Clone frame38 frameOut := frame.Clone()3940 // Form output image41 for ind := 0; ind < len(modelParams); ind++ {42 mp := modelParams[ind]43 parts := strings.Split(mp.modelName, "_")44 switch parts[0] {45 case "imagenet":46 // Get prediction47 res, err := mp.modelHandler.Get()48 if err == nil {49 mp.pred = res.Class50 }51 // Write prediction to frame52 gocv.PutText(53 &frameOut,54 mp.pred,55 image.Pt(10, ind*20+20),56 gocv.FontHersheyPlain, 1.2,57 bkgColor, 6,58 )59 // Write prediction to frame60 gocv.PutText(61 &frameOut,62 mp.pred,63 image.Pt(10, ind*20+20),64 gocv.FontHersheyPlain, 1.2,65 statusColor, 2,66 )67 case "emonet":68 // Get prediction69 res, err := mp.modelHandler.Get()70 if err != nil {71 break72 }73 // draw a rectangle around each face on the original image,74 // along with text identifying as "Human"75 var rMinY int76 for index, r := range res.Rects {77 gocv.Rectangle(&frameOut, r, boxColor, 2)78 if r.Min.Y-5 < 10 {79 rMinY = 1080 } else {81 rMinY = r.Min.Y82 }83 gocv.PutText(84 &frameOut,85 res.ClassArr[index],86 image.Pt(r.Min.X, rMinY),87 gocv.FontHersheyPlain, 1.2,88 bkgColor, 6,89 )90 gocv.PutText(91 &frameOut,92 res.ClassArr[index],93 image.Pt(r.Min.X, rMinY),94 gocv.FontHersheyPlain, 1.2,95 statusColor, 2,96 )97 }98 default:99 log.Fatal("Model not recognised")100 }101102 // Post next frame103 mp.modelHandler.Post(models.Input{Img: frame})104 }105106 // Write image to output Kafka queue107 select {108 case videoDisplay <- frameOut:109 default:110 }111 // videoDisplay <- frameOut112113 return nil114}115116type topicMsg struct {117 Mat []byte `json:"mat"`118 Channels int `json:"channels"`119 Rows int `json:"rows"`120 Cols int `json:"cols"`121 Type gocv.MatType `json:"type"`122} ...

Full Screen

Full Screen

captcha_gen.go

Source:captcha_gen.go Github

copy

Full Screen

1package main2import (3 "gocv.io/x/gocv"4 "image"5 "image/color"6 "math/rand"7 "strconv"8)9func getLowBrightnessRGBA() color.RGBA {10 r, g, b := color.YCbCrToRGB(uint8(rand.Intn(128)), uint8(rand.Intn(256)), uint8(rand.Intn(256)))11 return color.RGBA{R: r, G: g, B: b, A: 255}12}13func getImg() gocv.Mat {14 mat := <-imageChannel15 background.CopyTo(&mat)16 return mat17}18func genFormula() (int, int, *operator) {19 opIndex := rand.Intn(4)20 op := dic[opIndex]21 switch opIndex {22 // for + -23 case 0, 1:24 doubleDigits := rand.Intn(90) + 1025 singleDigit := rand.Intn(8) + 226 return doubleDigits, singleDigit, op27 // for *28 case 2:29 doubleDigits := rand.Intn(10) + 1030 singleDigit := rand.Intn(1) + 231 return doubleDigits, singleDigit, op32 // for /33 case 3:34 doubleDigits := rand.Intn(10) + 1035 singleDigit := rand.Intn(1) + 236 return doubleDigits * singleDigit, doubleDigits, op37 }38 // never happened39 return 0, 0, nil40}41// Bottom-left corner of the text string in the image.https://docs.opencv.org/4.x/d6/d6e/group__imgproc__draw.html#ga5126f47f883d730f633d74f07456c57642func genLocation(xPadding, maxX, maxY int, str string) image.Point {43 size := gocv.GetTextSize(str, gocv.FontHersheyScriptComplex, 1, 4)44 var x int45 if maxX-size.X <= 0 {46 x = xPadding47 } else {48 x = rand.Intn(maxX-size.X) + xPadding49 }50 y := rand.Intn(maxY-size.Y) + size.Y51 return image.Point{52 X: x,53 Y: y,54 }55}56func gen() ([]byte, string, error) {57 a, b, op := genFormula()58 mat := getImg()59 for i := 0; i < 10; i++ {60 gocv.Line(&mat,61 image.Point{X: rand.Intn(width / 2), Y: rand.Intn(height)},62 image.Point{X: rand.Intn(width/2) + width/2, Y: rand.Intn(height)},63 getLowBrightnessRGBA(),64 rand.Intn(3)+1)65 }66 matA := getImg()67 gocv.Blur(mat, &matA, image.Point{X: 8, Y: 8})68 imageChannel <- mat69 //* 20,23 //高度是2370 gocv.PutText(&matA, strconv.Itoa(a),71 genLocation(0, 80, height, strconv.Itoa(a)), gocv.FontHersheySimplex, 1, getLowBrightnessRGBA(), 4)72 gocv.PutText(&matA, op.o,73 genLocation(80, 30, height, op.o), gocv.FontHersheySimplex, 1, getLowBrightnessRGBA(), 4)74 gocv.PutText(&matA, strconv.Itoa(b),75 genLocation(110, 30, height, strconv.Itoa(b)), gocv.FontHersheySimplex, 1, getLowBrightnessRGBA(), 4)76 gocv.PutText(&matA, "=",77 genLocation(140, 30, height, "="), gocv.FontHersheySimplex, 1, getLowBrightnessRGBA(), 4)78 gocv.PutText(&matA, "?",79 genLocation(170, 30, height, "?"), gocv.FontHersheySimplex, 1, getLowBrightnessRGBA(), 4)80 buffer, err := gocv.IMEncode(gocv.PNGFileExt, matA)81 imageChannel <- matA82 if err != nil {83 return nil, "", err84 }85 return buffer.GetBytes(), strconv.Itoa(op.f(a, b)), nil86}...

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 window := gocv.NewWindow("Hello")4 img := gocv.NewMat()5 defer img.Close()6 defer window.Close()7 fmt.Println("Start reading camera device: 0")8 webcam, err := gocv.OpenVideoCapture(0)9 if err != nil {10 fmt.Println("Error opening the camera")11 }12 defer webcam.Close()13 img = gocv.NewMatWithSize(480, 640, gocv.MatTypeCV8UC3)14 pt := gocv.NewPoint2f(10, 50)15 blue := gocv.NewScalar(255, 0, 0, 0)16 for {17 if ok := webcam.Read(&img); !ok {18 fmt.Println("Cannot read device")19 }20 if img.Empty() {21 }22 gocv.PutText(&img, text, pt, fontFace, fontScale, blue, thickness)23 window.IMShow(img)24 if window.WaitKey(1) >= 0 {25 }26 }27}28pt := gocv.NewPoint2f(10, 50)29blue := gocv.NewScalar(255, 0, 0, 0)30gocv.PutText(&img, text, pt, fontFace, fontScale

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World!")4}5import "fmt"6func main() {7 fmt.Println("Hello World!")8}9import "fmt"10func main() {11 fmt.Println("Hello World!")12}13import "fmt"14func main() {15 fmt.Println("Hello World!")16}17import "fmt"18func main() {19 fmt.Println("Hello World!")20}21import "fmt"22func main() {23 fmt.Println("Hello World!")24}25import "fmt"26func main() {27 fmt.Println("Hello World!")28}29import "fmt"30func main() {31 fmt.Println("Hello World!")32}33import "fmt"34func main() {35 fmt.Println("Hello World!")36}37import "fmt"38func main() {39 fmt.Println("Hello World!")40}41import "fmt"42func main() {43 fmt.Println("Hello World!")44}45import "fmt"46func main() {47 fmt.Println("Hello World!")48}49import "fmt"50func main() {51 fmt.Println("Hello World!")52}53import "fmt"54func main() {55 fmt.Println("Hello World

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 img := image.NewRGBA(image.Rect(0, 0, 1000, 1000))4 red := color.RGBA{255, 0, 0, 255}5 green := color.RGBA{0, 255, 0, 255}6 blue := color.RGBA{0, 0, 255, 255}7 for i := 0; i < 1000; i++ {8 for j := 0; j < 1000; j++ {9 img.Set(i, j, red)10 }11 }12 for i := 100; i < 900; i++ {13 for j := 100; j < 900; j++ {14 img.Set(i, j, green)15 }16 }17 for i := 200; i < 800; i++ {18 for j := 200; j < 800; j++ {19 img.Set(i, j, blue)20 }21 }22 for i := 0; i < 1000; i++ {23 for j := 0; j < 1000; j++ {24 if i == j {25 img.Set(i, j, color.RGBA{255, 255, 255, 255})26 }27 }28 }29 myImageFile, _ := os.Create("myImage.jpg")30 jpeg.Encode(myImageFile, img, &opt)31 myImageFile.Close()32 myImageFile, _ = os.Open("myImage.jpg")33 myImage, _ := jpeg.Decode(myImageFile)34 dst := image.NewRGBA(myImage.Bounds())35 draw.Draw(dst, myImage.Bounds(), myImage, image.ZP, draw.Src)

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello World")4}5import "fmt"6func main() {7 fmt.Println("Hello World")8}9import "fmt"10func main() {11 fmt.Println("Hello World")12}13import "fmt"14func main() {15 fmt.Println("Hello World")16}17import "fmt"18func main() {19 fmt.Println("Hello World")20}21import "fmt"22func main() {23 fmt.Println("Hello World")24}25import "fmt"26func main() {27 fmt.Println("Hello World")28}29import "fmt"30func main() {31 fmt.Println("Hello World")32}33import "fmt"34func main() {35 fmt.Println("Hello World")36}37import "fmt"38func main() {39 fmt.Println("Hello World")40}41import "fmt"42func main() {43 fmt.Println("Hello World")44}45import "fmt"46func main() {47 fmt.Println("Hello World")48}49import "fmt"50func main() {51 fmt.Println("Hello World")52}53import "fmt"54func main() {55 fmt.Println("Hello World

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := image.NewRGBA(image.Rect(0, 0, 800, 600))4 draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)5 f, err := os.Create("out.jpg")6 if err != nil {7 log.Fatal(err)8 }9 err = jpeg.Encode(f, m, &jpeg.Options{jpeg.DefaultQuality})10 if err != nil {11 log.Fatal(err)12 }13}14import (15func main() {16 m := image.NewRGBA(image.Rect(0, 0, 800, 600))17 draw.Draw(m, m.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src)

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 img := opencv.LoadImage("1.jpg")4 defer img.Release()5 font := opencv.InitFont(opencv.CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 1, 8)6 opencv.PutText(img, "Hello, world!", opencv.Point{50, 50}, font, opencv.Scalar{0, 255, 0, 0})7 opencv.SaveImage("2.jpg", img, 0)8 fmt.Println("Image saved to 2.jpg")9}10import (11func main() {12 img := opencv.LoadImage("1.jpg")13 defer img.Release()14 font := opencv.InitFont(opencv.CV_FONT_HERSHEY_COMPLEX, 1, 1, 0, 1, 8)15 img.PutText("Hello, world!", opencv.Point{50, 50}, font, opencv.Scalar{0, 255, 0, 0})16 opencv.SaveImage("2.jpg", img, 0)17 fmt.Println("Image saved to 2.jpg")18}

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 src := gocv.IMRead("test.png", gocv.IMReadColor)4 if src.Empty() {5 fmt.Println("Error reading image from: ", "test.png")6 }7 defer src.Close()8 dst := gocv.NewMat()9 defer dst.Close()10 gocv.CvtColor(src, &dst, gocv.ColorBGRToGray)11 window := gocv.NewWindow("Put Text")12 defer window.Close()13 window.IMShow(dst)14 window.WaitKey(0)15}16import (17func main() {18 src := gocv.IMRead("test.png", gocv.IMReadColor)19 if src.Empty() {20 fmt.Println("Error reading image from: ", "test.png")21 }22 defer src.Close()23 dst := gocv.NewMat()24 defer dst.Close()25 gocv.CvtColor(src, &dst, gocv.ColorBGRToGray)26 window := gocv.NewWindow("Put Text")27 defer window.Close()28 window.IMShow(dst)29 window.WaitKey(0)30}31import (

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import "gocv.io/x/gocv"2func main() {3 img := gocv.IMRead("test.png", gocv.IMReadColor)4 if img.Empty() {5 panic("Error reading image")6 }7 s := img.Size()8 scale := float64(s[0]) / 400.09 thick := int(math.Ceil(scale * 1.5))10 size := gocv.GetTextSize("Hello World", ft, scale, thick, &baseline)11 pt := image.Pt((s[0]-size.X)/2, (s[1]+size.Y)/2)12 gocv.PutText(&img, "Hello World", pt, ft, scale, color.RGBA{0, 0, 255, 0}, thick)13 gocv.IMWrite("result.png", img)14 gocv.DestroyAllWindows()15}16scale := float64(s[0]) / 400.017thick := int(math.Ceil(scale * 1.5))18size := gocv.GetTextSize("Hello World", ft, scale, thick, &baseline)19pt := image.Pt((s[0]-size.X)/2, (s[1]+size.Y)/2)

Full Screen

Full Screen

putText

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 imageFile, err := os.Open("1.jpg")4 if err != nil {5 fmt.Println(err)6 }7 defer imageFile.Close()8 image, _, err := image.Decode(imageFile)9 if err != nil {10 fmt.Println(err)11 }12 newImageFile, err := os.Create("2.jpg")13 if err != nil {14 fmt.Println(err)15 }16 defer newImageFile.Close()17 newImage := image.NewRGBA(image.Bounds())18 color := color.RGBA{255, 255, 255, 255}19 image = putText(image, "Hello World", color, x, y, fontSize)20 jpeg.Encode(newImageFile, newImage, nil)21}22func putText(img image.Image, text string, color color.RGBA, x int, y int, fontSize float64) image.Image {23 newImage := image.NewRGBA(img.Bounds())24 draw.Draw(newImage, newImage.Bounds(), img, image.Point{0, 0}, draw.Src)25 font, err := freetype.ParseFont(goregular.TTF)26 if err != nil {27 fmt.Println(err)28 }29 c := freetype.NewContext()30 c.SetDPI(72)31 c.SetFont(font)32 c.SetFontSize(12)33 c.SetClip(newImage.Bounds())34 c.SetDst(newImage)35 c.SetSrc(image.NewUniform(color))36 c.SetFontSize(fontSize)37 pt := freetype.Pt(x, y+int(c.PointToFixed(fontSize)>>6))38 _, err = c.DrawString(text, pt)39 if err != nil {40 fmt.Println(err

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful