Cannot retrieve data from firebase '400 Bad Request' - python

I trying to retrieve data from firebase but it give me this error
Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://linkfirebase.firebasedatabase.app/GSBACILLI5%0A resulted in a 400 Bad Request response.
the reference is GSBACILLI5, but why the path to request data is GSBACILLI5%0A?
Btw, GSBACILLI5 is decode from QR code using webcam in python, did it give any problem to the path?
This is my code to call python program in PHP
$commandString = "python trackqr3.py";
$outpy=popen($commandString, 'r');
$contents = '';
#while (!feof($outpy)) {
foreach ((array)$outpy as $outpy){
$contents .= fread($outpy, 8192);
}
And this is my python script
import cv2
def capture():
# initialize the cv2 QRCode detector
detector = cv2.QRCodeDetector()
while True:
_, img = cap.read()
# detect and decode
data, bbox, _ = detector.detectAndDecode(img)
# check if there is a QRCode in the image
if data:
a=data
print(a)
return a
#break
cv2.imshow("QRCODEscanner", img)
#if cv2.waitKey(1) == ord("q"):
# break
cv2.waitKey(1)
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)
id=capture()
cap.release()
#print('ID:',id)
cv2.destroyAllWindows()

%0A means new line (Enter). Code hex(ord("\n")) gives 0A.
You send reference using print() but print() automatically add new line at the end of string.
You have to use end="" to skip new line
print(a, end="")
OR in PHP you should remove/strip this new line.
But I don't remeber what function in PHP it needs.

Related

Port missing in uri warning: Error opening file with Python OpenCV cv2.VideoCapture()

I got a blunder as depicted beneath when I endeavor to stream ipcam
"[tcp # 000000000048c640] Port missing in uri
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)"
import numpy as np
import cv2
cv2.__file__
cap = cv2.VideoCapture('http://admin:password#http://192.168.1.***/')
#cap = cv2.VideoCapture('https://www.youtube.com/watch?v=Mus_vwhTCq0')
while(True):
ret, frame = cap.read()
try:
cv2.resizeWindow('Stream IP Camera OpenCV', 120300, 800)
cv2.imshow('Stream IP Camera OpenCV',frame)
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)
print (message)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
First open VLC player and ensure your ipcam stream link is working. If it works, we can now check if OpenCV can connect to the camera with isOpened() and check the frame retrieval status:
while True:
if cap.isOpened():
ret, frame = cap.read()
if ret:
# Process here
Start with making the url working in VLC. Try this website to get a working link/port/user/password combination that works for you camera.

Problem streaming from IP camera with python openCV

Before asking this question I searched the site for a similar problem for the last 2 days but I couldn't find the one specific to me.
I have an IP camera whose IP address, username, etc. I have been given full access to. I can actually open the stream and watch it live by writing the IP into VLC Player >> Open Network Stream >> Network.
But what I want is to be able to watch the same live stream with python. Here's my code:
import urllib.request
import cv2
import numpy
url = 'rtsp://10.10.111.200/profile2/media.smp'
while True:
resp = urllib.request.urlopen(url)
b_array = bytearray(resp.read())
img_np = numpy.array(b_array, dtype=numpy.uint8)
img = cv2.imdecode(img_np, -1)
cv2.imshow('test', img)
if cv2.waitkey(10) == ord('q'):
exit(0)
When I run this code, it gives me the following error:
urllib.error.URLError: .
Then I figured that maybe I should change rtsp to http in url, but when I do, it gives me the following error,
cv2.error: OpenCV(3.4.3)
D:\Build\OpenCV\opencv-3.4.3\modules\imgcodecs\src\loadsave.cpp:737:
error: (-215:Assertion failed) !buf.empty() && buf.isContinuous() in
function 'cv::imdecode_' in the line img = cv2.imdecode(img_np,
-1)
which I think is because there's no data coming from the (very likely wrong since I changed to http) source.
I'm on Windows 10 64bit.
The library you are using to read the data stream does not support the rtsp protocol so it will never work, maybe you can use the following instead:
import cv2
capture_video = cv2.VideoCapture('rtsp://10.10.111.200/profile2/media.smp')
while(True):
ret, img = capture_video.read()
cv2.imshow('Test', img)
if cv2.waitKey(10) == ord('q'):
exit(0)

I need hikvision camera which has ip 20.0.0.14 and user name/password is admin/12345 to run by python code

I need hikvision camera which has ip 20.0.0.14 and user name/password is admin/12345 to run by python code
the original camera code is
import cv2.cv as cv
import time
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break
cv.DestroyAllWindows()
i need help please
Here's the solution when using OpenCV3. In your sample code, you are not only not using the OpenCV2 interface, but you are accessing the very old cv (prior to OpenCV 2) interface. So my first suggestion is to get a current install of OpenCV working.
Possible source of rtsp urls for use with hikvision cameras:
https://www.ispyconnect.com/man.aspx?n=Hikvision
import cv2
# Note the following is the typical rtsp url for streaming from an ip cam
# source = "rtsp://user:password#ipaddress:port/<camera specific stuff>"
# Each manufacturer is different. For my alibi cameras, this would be
# a valid url to use with the info you provided.
source = "rtsp://admin:12345#20.0.0.14//Streaming/Channels/2"
cap = cv2.VideoCapture(source)
ok_flag = True
while ok_flag:
(ok_flag, img) = cap.read()
if not ok_flag: break
cv2.imshow("some window", img)
if cv2.waitKey(10) == 27:
break
cv2.destroyAllWindows()
Also note that this code works the same if the source is the path to a valid video file (like an .avi), or for a web camera (in which case you pass the integer number of the webcam, like 0).
Another error in your post is the cv.CaptureFromCAM(0), which would be capturing from the first webcam installed on the computer, not an ip stream.

Reading camera input from /dev/video0 in python or c

I want to read from the file /dev/video0 either through c or python,and store the incoming bytes in a different file.
Here is my c code:
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main()
{
int fd,wfd;
fd=open("/dev/video0",O_RDONLY);
wfd=open("image",O_RDWR|O_CREAT|O_APPEND,S_IRWXU);
if(fd==-1)
perror("open");
while(1)
{
char buffer[50];
int rd;
rd=read(fd,buffer,50);
write(wfd,buffer,rd);
}
return 0;
}
When i run this code and after some time terminate the program nothing happens except a file name "image" is generated which is usual.
This is my python code:
image=open("/dev/video0","rb")
image.read()
and this is my error when my run this snippet:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IOError: [Errno 22] Invalid argument
I want to know how to do this using pure c or python code.Please no external library suggestions.
It's not so easy.
Most cameras won't work in read/write mode. You need to use Streaming I/O mode - for example memory mapping.
You need to set pixel format - YUYV/RGB/MJPEG, bytes per pixel, resolution.
You have to start grabbing, read and save at least one frame.
Further to my comment, here's an example of displaying a video stream from video on disk (see documentation):
import numpy as np
import cv2
video = "../videos/short.avi"
video_capture = cv2.VideoCapture(video)
while(True):
# Capture frame-by-frame
ret, frame = video_capture.read()
# Our operations on the frame comes here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything's done, release the capture
video_capture.release()
cv2.destroyAllWindows()

How to view video stream in OpenCV2 python

I'm starting to play with Opencv. I am using the python bindings for opencv2 on Linux. I wrote a quick test program but it seems to hang indefinitely.
import cv2
weblink = "http://continuous-video-stream-here"
cv2.namedWindow("video")
vid = cv2.VideoCapture(weblink)
key = -1
while (key < 0):
success, img = vid.read()
cv2.imshow("video", img)
But it hangs on this output:
(video:14388): GStreamer-CRITICAL **: gst_caps_unref: assertion `caps != NULL' failed
I have also tried reading from urllib2:
vid = cv2.VideoCapture(urllib2.urlopen(weblink).read())
But that didn't work either.
I am using Opencv 2.4.2, ffmpeg-0.11.2
EDIT: The video feed uses realplayer to display the video over http in the browser.
Code safely and test the return of the method:
vid = cv2.VideoCapture(weblink)
if not vid:
print("!!! Failed VideoCapture: invalid parameter!")
The address you are using is probably not supported by OpenCV.
The same practice should be used whenever a method can fail:
while (key < 0):
success, img = vid.read()
if not img:
print("!!! Failed vid.read()")
break
cv2.imshow("video", img)

Categories

Resources