douxi8119 2017-02-20 16:59
浏览 129

使用“ github.com/blackjack/webcam”库为以go语言编写的视频流加水印

I want to watermark "the video streaming over http" which is written in GO language by using blackjack library. And for this, I found a code watermarking with png. But I could not manage to transform the variables jpeg <-> byte[].

Here is the code part which gets the frame from cam and writes to "JpegImage" variable.

var jpegImage []byte   
frame, err := cam.ReadFrame()
if len(frame) != 0 {
    mutex.Lock()
    jpegImage = frame
    mutex.Unlock()
} 
else if err != nil {
    panic(err.Error())
}

And here is the watermarking code with "image.jpg" variable.

imgb, _ := os.Open("image.jpg")
img, _ := jpeg.Decode(imgb)
defer imgb.Close()

wmb, _ := os.Open("watermark.png")
watermark, _ := png.Decode(wmb)
defer wmb.Close()

offset := image.Pt(200, 200)
b := img.Bounds()
m := image.NewRGBA(b)
draw.Draw(m, b, img, image.ZP, draw.Src)
draw.Draw(m, watermark.Bounds().Add(offset), watermark, image.ZP, draw.Over)

imgw, _ := os.Create("watermarked.jpg")
jpeg.Encode(imgw, m, &jpeg.Options{jpeg.DefaultQuality})
defer imgw.Close()

In the end, I need to combine this two code parts. After getting the frame from cam; firstly transform it to jpg, secondly watermark with png, thirdly transform it to []byte and lastly assign it to "JpegImage" variable.

I hope you can help me please.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退