Ask Your Question

MoyliePi's profile - activity

2020-04-12 10:45:28 -0600 received badge  Famous Question (source)
2019-02-27 18:28:18 -0600 received badge  Notable Question (source)
2019-02-11 23:52:15 -0600 received badge  Famous Question (source)
2018-09-29 02:24:35 -0600 received badge  Popular Question (source)
2018-08-15 06:41:52 -0600 received badge  Notable Question (source)
2018-06-28 01:02:59 -0600 received badge  Popular Question (source)
2017-12-07 07:11:51 -0600 commented answer Error: "mat is not a numpy array, neither a scalar"?

Thanks for the help again! I'll take another swing at this.

2017-12-06 15:46:41 -0600 marked best answer Error: "mat is not a numpy array, neither a scalar"?

I am trying to run 4 USB cameras and feed them to a monitor. I would like to have the frames of each camera split vertically and horizontally on the monitor so one can see all four feeds at once. I am getting the error noted in the "question". What does this mean? PS - I am a newbie at coding and my knowledge is limited.

import cv2 
import numpy as np

cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
cap3 = cv2.VideoCapture(2)
cap4 = cv2.VideoCapture(3)

while(cap1.isOpened()):
ret, frame = cap1.read()
if ret==True:
cv2.imshow('Left Mold - Cavity 1 & 2', cap1)

while(cap2.isOpened()):
ret, frame = cap2.read()
if ret==True:
cv2.imshow('Left Mold - Cavity 2 & 3', cap2)

while(cap3.isOpened()):
ret, frame = cap3.read()
if ret==True:
cv2.imshow('Right Mold - Cavity 1 & 2', cap3)

while(cap4.isOpened()):
ret, frame = cap4.read()
if ret==True:
cv2.imshow('Right Mold - Cavity 3 & 4', cap4)

cap1.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap1.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap2.set(cv2.CAP_PROP_FRAME_WIDTH, 320); 
cap2.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap3.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap3.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);
cap4.set(cv2.CAP_PROP_FRAME_WIDTH, 320);
cap4.set(cv2.CAP_PROP_FRAME_HEIGHT, 240);

#Stack camera 1 & 3 vertically and camera 2 & 4 horizontally to 1 & 3
numpy_vertical = np.vstack((cap1, cap3))
numpy_horizontal = np.hstack((cap2, cap4))
array([[cap1,cap2],
[cap3,cap4]])

#Put the camera feed on the specified axis
numpy_vertical_concat = np.concatenate((cap1, cap3), axis=0)
numpy_horizontal_concat = np.concatenate((cap2, cap4), axis=1)

key = cv2.waitKey(20)
if key == 27: # exit on ESC
sys.exit()

#When everything is done, release the capture

cap1.release()
cap2.release()
cap3.release()
cap4.release()
cv2.destroyAllWindows()
2017-12-06 14:40:31 -0600 asked a question Error: "mat is not a numpy array, neither a scalar"?

Error: "mat is not a numpy array, neither a scalar"? I am trying to run 4 USB cameras and feed them to a monitor. I woul

2017-12-06 14:31:47 -0600 edited question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably

2017-12-06 14:30:34 -0600 commented question Is there a way to resize an image and a window simultaneously?

Haha, okay I will do that.

2017-12-06 14:29:50 -0600 edited question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably

2017-12-06 14:29:27 -0600 edited question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably

2017-12-06 14:21:03 -0600 edited question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably

2017-12-06 14:17:17 -0600 commented question Is there a way to resize an image and a window simultaneously?

No sir. See below. pi@MoyliePi:~ $ python CamREV2.py Traceback (most recent call last): File "CamREV2.py", line 12, i

2017-12-06 13:49:20 -0600 commented question Is there a way to resize an image and a window simultaneously?

what does "mat is not a numpy array, neither a scalar" mean? - google search isn't pulling anything up for the term "mat

2017-12-06 10:50:35 -0600 commented question Is there a way to resize an image and a window simultaneously?

Yeah I'm not even sure if the RaspberryPi3 can handle the 4 cams but my boss said give it a whirl! Thanks for the info t

2017-12-06 09:55:26 -0600 received badge  Editor (source)
2017-12-06 09:55:26 -0600 edited question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably

2017-12-06 07:05:44 -0600 commented question Is there a way to resize an image and a window simultaneously?

Thanks @berak! I appreciate the help.

2017-12-05 15:17:26 -0600 commented answer Is there a way to resize an image and a window simultaneously?

Awesome, thanks! I'll go do some research and see how it works out...I may be back haha.

2017-12-05 15:07:20 -0600 received badge  Supporter (source)
2017-12-05 15:07:14 -0600 marked best answer Is there a way to resize an image and a window simultaneously?

I am a rookie at coding and even with that I am probably being generous. I was wondering if there is a way to resize an image, fed by a USB webcam, and resize a window simultaneously? With the Raspberry Pi3, I am trying to run four USB cameras and display the feed on a monitor. The monitor is a 21.5" so I want to have an even vertical and horizontal split in the screen so that I can view all four cameras at once. I created/cut and pasted a script written in Python and using opencv and numpy. Any ideas?

import cv2

import numpy as np

vc = cv2.VideoCapture(0)

if vc.isOpened(): # try to get the first frame
    rval, frame = vc.read()

else:
    rval = False

while rval:
     cv2.resizeWindow("Left Mold - Cavity 1 & 2", 20, 20)

    cv2.moveWindow("Left Mold - Cavity 1 & 2", 1, 1)

    cv2.imshow("Left Mold - Cavity 1 & 2", frame)

    rval, frame = vc.read()

    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
        break

cv2.destroyWindow("Left Mold - Cavity 1 & 2")

So I revised the code but I did something wrong along the way because I get some kickbacks. Here is the revised code...

import cv2 
import numpy as np

cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)
cap3 = cv2.VideoCapture(2)
cap4 = cv2.VideoCapture(3)

while(True):
    #Read Camera 1
    ret, frame = cap1.read()
    #Read Camera 2
    ret, frame = cap2.read()
    #Read Camera 3
    ret, frame = cap3.read()
    #Read Camera 4
    ret, frame = cap4.read()

    #Reduce the image size of all camera feeds to half
    cap1 = cv2.resize(cap1, (0, 0), None, .5, .5)
    cap2 = cv2.resize(cap2, (0, 0), None, .5, .5)
    cap3 = cv2.resize(cap3, (0, 0), None, .5, .5)
    cap4 = cv2.resize(cap4, (0, 0), None, .5, .5)

    #Stack camera 1 & 3 vertically and camera 2 & 4 horizontally to 1 & 3
    numpy_vertical = np.vstack((cap1, cap3))
    numpy_horizontal = np.hstack((cap2, cap4))
    array([[cap1,cap2],
           [cap3,cap4]])

    #Put the camera feed on the specified axis
    numpy_vertical_concat = np.concatenate((cap1, cap3), axis=0)
    numpy_horizontal_concat = np.concatenate((cap2, cap4), axis=1)

    #Display the video feed
    cv2.imshow('Left Mold - Cavity 1 & 2', cap1)
    cv2.imshow('Left Mold - Cavity 3 & 4', cap2)
    cv2.imshow('Right Mold - Cavity 1 & 2', cap3)
    cv2.imshow('Right Mold - Cavity 3 & 4', cap4)

    key = cv2.waitKey(20)
    if key == 27: # exit on ESC
        break

#When everything is done, release the capture

    cap1.release()
    cap2.release()
    cap3.release()
    cap4.release()
    cv2.destroyAllWindows()

And here are the errors...

VIDIOC_DQBUF: No such device
libv4l2: error turning on stream: Input/output error
VIDIOC_STREAMON: Input/output error
Traceback (most recent call last):
  File "MultipleVid.py", line 20, in <module>
    cap1 = cv2.resize(cap1, (0, 0), None, .5, .5)
TypeError: src is not a numpy array, neither a scalar
Unable to stop the stream.: No such device
Unable to stop the stream.: No such device
Unable to stop the stream.: No such ...
(more)
2017-12-05 15:07:13 -0600 received badge  Scholar (source)
2017-12-05 15:06:59 -0600 commented answer Is there a way to resize an image and a window simultaneously?

That's great! Thank-you for the quick response. I like the method of reading the individual frames and then scale the la

2017-12-05 14:34:48 -0600 asked a question Is there a way to resize an image and a window simultaneously?

Is there a way to resize an image and a window simultaneously? I am a rookie at coding and even with that I am probably