On 8/11/21 2:27 AM, Kevin Lo wrote:
On Tue, Aug 10, 2021 at 12:32:36PM -0600, Jeff Ross wrote:
Hello!

This is a follow-up to a post I made to misc@ about OpenCV not being able to
open a camera to capture images.?? Switching to ports@ as this seems more
appropriate for this error.

https://marc.info/?l=openbsd-misc&m=162853582527839&w=2

Kevin Lo had also run into the problem and had submitted a patch:

https://marc.info/?l=openbsd-ports-cvs&m=162857744213080&w=2

I built the new version of OpenCV 4.5.2 today and yes, it can open the
camera, but attempting to capture an image prints the following for each
image: [ WARN:0] global
/usr/ports/pobj/opencv-4.5.2/opencv-4.5.2/modules/videoio/src/cap_v4l.cpp
(798) requestBuffers VIDEOIO(V4L2:/dev/video0): no support for memory
mapping [ WARN:0] global
/usr/ports/pobj/opencv-4.5.2/opencv-4.5.2/modules/videoio/src/cap_v4l.cpp
(777) requestBuffers VIDEOIO(V4L2:/dev/video0): Insufficient buffer memory
Trying to access the list of captured images yields this: OpenCV(4.5.2)
/usr/ports/pobj/opencv-4.5.2/opencv-4.5.2/modules/core/src/matrix.cpp:456:
error: (-215:Assertion failed) total() == 0 || data != NULL in function
'Mat' Exception caught! OpenCV(4.5.2)
/usr/ports/pobj/opencv-4.5.2/opencv-4.5.2/modules/core/src/matrix.cpp:456:
error: (-215:Assertion failed) total() == 0 || data != NULL in function
'Mat' At that point my python script exits due to the exception. OpenCV docs
don't seem to get into buffer management other than via an internal function
to be used only by OpenCV. Would this be a missing parameter in how OpenCV
is built or is it something I can control from a sysctl of some kind? dmesg
follows but this stick computer has 4G of ram and doesn't have much anything
running on it. Thanks!
You tested your open_test.py?  If so, I tested it on my X1E, works for me:
http://ix.io/3vD3

Yes, I tested it against the open_test.py script and that simple script works here as well.  I do notice that you also got the warning about "no support for memory mapping" although maybe not the "Insufficient buffer memory" error.

Moving on to something more complex though, the script I'm currently running to catch night sky images absolutely does not work.

On the raspberry pi 3B+ I'm trying to replace, I do not see either the warning or the error.  OpenCV docs (https://docs.opencv.org/master/d1/dfb/intro.html) in the Memory Management Section says explicitly that "OpenCV handles all the memory automatically."  These error messages ("no support for memory mapping" and "insufficient buffer memory") suggest that this not happening with this build of OpenCV.

It is possible that this is actually a numpy error but I don't know how to narrow that down.

Jeff

<working code on the rpi3b+):


    if day_or_night == "day":
        subprocess.check_output("mkdir -p /starhouse/skyfield_opencv_cam/day/%s" % (dir_date),stderr=subprocess.STDOUT, shell=True)
        print_free_memory("start")
        gc.collect()
        z = 0
        frame = []
        epoch_filename = []
        logging("Elapsed time before capturing frames: %s" % (time.time() - start))
        while z < frameFrequency:
            try:
                ret, temp_frame = cap.read()
                if ret is False:
                    break
                frame.append(temp_frame)
                logging("Elapsed time after snapshot #%s: %s" % (z,time.time() - start))
                total_frame += 1
            except Exception as e:
                logging(e)
                logging("Exception caught! %s" % (e))
            z += 1
        logging("Elapsed time after capturing %s images: %s" % (z,time.time() - start))

        #we now have frameFrequency images as a series of numpy arrays
        alpha = .3
        beta = (1 - alpha)
        a = 0
        dst = frame[0]
        dst32 = dst.astype(np.int32)
        while a <  len(frame):
            image_name = "/starhouse/skyfield_opencv_cam/day/%s/%s" % (dir_date,str(time.time()) + ".jpg")
            cv.imwrite(image_name, frame[a])
            dst32 = cv.add(dst32,frame[a].astype(np.int32))
            a += 1
        dst = cv.normalize(dst32,None,0,255,cv.NORM_MINMAX) #opencv normalization
        epoch_filename = "4K_spinel_day_" + str(time.time()) + ".jpg"
        image_name = "/starhouse/skyfield_opencv_cam/day/%s/%s" % (dir_date,epoch_filename)
        cv.imwrite(image_name, dst)
        logging("Elapsed time after writing %s images: %s" % (z,time.time() - start))

On the OpenBSD  stick it fails on the "dst = frame[0]" line because the frame arrays have not been filled by the previous reads.

Hope that helps!

Jeff

Reply via email to