Mat m = new Mat (720, 1280, CvType.CV_8UC4);
m.put(0,0,vf.rawData.getBytes());
Imgproc.putText(m, "Welcomeeeeeeeeeeeeeee", new org.opencv.core.Point(400,400),
Core.FONT_HERSHEY_PLAIN, 1.0 ,new Scalar(255,0,0));
//byte[] buffer = new byte[((int)m.total())*m.channels()];
byte[] buffer = new byte[vf.rawData.getBytes().length];
m.get(0,0,buffer);
FileOutputStream fos = new FileOutputStream("C:/Users/h130954/images/Image-" + BAbsTime.now().getTimeOfDayMillis() +".jpg");
fos.write(buffer);
fos.close();
I am trying to insert text welcome into frame, but its not working. The image does not contain the text I am trying to add
I'm not very experienced with Java, but nothing there does any encoding into the JPEG format, does it? If you have a JPEG image, you can't just put it into a Mat. You have to decode it first. If you have a Mat, you can't just stuff the bytes into a JPEG file and expect to see anything, you have to encode it first.
The frame is from live video and It’s jpeg only, I am converting frame to mat and trying to add text and then converting back to bytes. How to encode and decode, how to do this in OpenCV
btw, if the input was from a video, it's probably CV_8UC3, not CV_8UC4
and i somehow suspect, you don't need that byte[] buffer at all. you could simply use
imwrite()
, to save your Mat to disc.CV_8UC3 did not work for me, CV_8UC4 works for me. Below are the steps I am doing: 1>Taking frame from video, which is in bytes 2> creating mat object for it 3> Modifying Mat Object and inserting text using putText 4> then again converting mat object back to bytes.(decoding frames) 5> This bytes is displayed video.
Do I need to do Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY); to insert text???
Also this video is from Axis IP camera
Do I need to encode/decode??
again no, you don't need any byte[] buffers.