Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers. Note that due to large amounts of spam attempts, your first three posts will be manually moderated, so please be patient.
Because of un-manageable amounts of spam despite our use of CAPTCHAs, email authorization, and other tools, we have discontinued this forum (see the 700k+ registered users with validated email addresses at right?). Please email us any questions or post bug reports and feature requests on GitHub at https://github.com/jevois -- The content below remains available for future reference.

use opencv api

0 votes

I am more confortable using OpenCV API, so sometime I need to change frame provided by jevois camera with OpenCV and send it over USB. But it does not work as I am trying to do it.

To reproduce issue, I took PythonTest example, and I changed it little bit.

def process(self, inframe, outframe):
        jevois.LINFO("process with usb")

        # Get the next camera image (may block until it is captured):
        inimg = inframe.get()
        jevois.LINFO("Input image is {} {}x{}".format(jevois.fccstr(inimg.fmt), inimg.width, inimg.height))

        # Get the next available USB output image:
        outimg = outframe.get()
        jevois.LINFO("Output image is {} {}x{}".format(jevois.fccstr(outimg.fmt), outimg.width, outimg.height))

        # Example of getting pixel data from the input and copying to the output:
        jevois.paste(inimg, outimg, 0, 0)

        # We are done with the input image:
        inframe.done()

        # Example of in-place processing:
        jevois.hFlipYUYV(outimg)

        img = jevois.convertToCvRGB(outimg)
        # Example of simple drawings:
        cv2.circle(img, 
            (int(outimg.width/2), int(outimg.height/2)), 
            int(outimg.height/2.2),
            int(outimg.height/2.2))
        # jevois.drawCircle(outimg,   int(outimg.width/2), 
        #                             int(outimg.height/2), int(outimg.height/2.2),
        #                             2, jevois.YUYV.White)

        jevois.writeText(outimg, "Hi from Python!", 20, 20, jevois.YUYV.White, jevois.Font.Font10x20)
        
        # We are done with the output, ready to send it to host over USB:
        outframe.sendCvRGB(img)

        # Send a string over serial (e.g., to an Arduino). Remember to tell the JeVois Engine to display those messages,
        # as they are turned off by default. For example: 'setpar serout All' in the JeVois console:
        jevois.sendSerial("DONE frame {}".format(self.frame));
        self.frame += 1

Regards

asked Mar 21, 2018 in Programmer Questions by nadirloutfi (230 points)

1 Answer

+1 vote
 
Best answer
I think the problem is that you are getting the output image twice. We basically support two programming models for python:

- the easy one where you just get and send OpenCV images (numpy arrays).

- the more efficient and more fine-grained one where you get and send JeVois raw images.

In your code, the "outimg=outframe.get()" first requests a raw image buffer to be later sent over USB. But then the "outframe.sendCvBGR(img)" is a combined function that hides all the raw buffer interface from the user and assumes that we will only deal with OpenCV images; hence it will again request a raw buffer, then copy the OpenCV pixel data to it, then send the buffer over USB.

Have a look at this for more explanations on the differences:

http://jevois.org/doc/ModulePythonTutorial.html

To get started, I would recommend doing something like the sanbox module in that doc page. Once you get that working, you can have a look at the section about more fine-grained control if you want to further optimize your code for speed.
answered Mar 21, 2018 by JeVois (46,580 points)
selected Mar 21, 2018 by nadirloutfi
...