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.
Welcome to JeVois Tech Zone, where you can ask questions and receive answers from other members of the community.

How can I store a Video frame by frame to the sdcard of my A33 cam

+1 vote
I wrote a Python code for storing a video on the sd-card of my a33 cam. My problem is, that the Filename will be stored, but I cannot write frames after opening the file. Here you can see my Python code. In the line "jevois.sendSerial(str(cap.isOpened()))" i can read, wether the File is opened or not. I always get the answer "false" (that means File not opened). I do not know what is wrong, where is my mistake. Can everybody help me? Every Tipp will be ok. Thank you.

def VideoSpeichern(self, frame):

    jevois.sendSerial("VideoSpeichern")

    cap = cv2.VideoCapture(0)

    # Der Dateiname besteht aus Objekt, Datum und Uhrzeit. Dies wird hier zusammengefuegt.

    now = datetime.now() # aktuelles Datum und Uhrzeit

    date_object = now.strftime("%Y%m%d") # Heutiges Datum in date_object ablegen

    time_object = now.strftime("%H%M%S") # Aktuelle Uhrzeit in time_object ablegen

    PfadDatei = ("modules/Dambrowsky/OpenCVObjektErkennungBilderVideo/BilderVideos/     Person"+"_"+str(date_object)+"_"+str(time_object)+".avi")

    # codec definieren und VideoWriter Objekt erzeugen

    fourcc = cv2.VideoWriter_fourcc(*'DIVX')

    out = cv2.VideoWriter(PfadDatei,fourcc, 20.0, (640,480))

    jevois.sendSerial(str(cap.isOpened()))

    start = time.time()

    while(cap.isOpened()):

        ret, frame = cap.read()

        jevois.sendSerial(str(ret))

        if ret==True:

            frame = cv2.flip(frame,0)

            # frame in Datei schreiben

            out.write(frame)

            end = time.time()

            jevois.sendSerial(end - start)

            if (end - start > 30):

                key = ord('q')

                break

        else:

        break

    # Alles wieder am Ende schliessen

    cap.release()

    out.release()
asked Mar 2 in Programmer Questions by Peter (520 points)

1 Answer

0 votes
Looks like you are opening "cap" as a video capture device but that is not available in JeVois modules.

The core JeVois software does the capture for you. All you need is to write a process() function that will be called each time a new frame is available from the sensor. In that function you can save your frames. Make sure you make "out" a class data member of your module so that it persists across multiple calls to process()

Have a look here for some guidance:

http://jevois.org/tutorials/ProgrammerInvHello.html

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

Start with the code for Hello. Open "out" (renamed self.out) in __init__ of the module). Then in process() add your "out.write(frame)". I recommend that you use an absolute path for your saved video (e.g., /jevois/myvideo.avi)
answered Mar 11 by JeVois (46,200 points)
...