1

>> my py script is running fine but when i created .py to .exe the below error is generated.

OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): http://admin:admin@192.168.1.86/axis-cgi/mjpg/video.cgi in function 'cv::icvExtractPattern'

My py script is below and its generate.

import face_recognition
import cv2
import time
import requests
import json
from http.client import responses
from datetime import datetime 
from datetime import timedelta
import sys
from truepy import License
from getmac import get_mac_address as gma
import easygui



# global variables
ChangeLayoutTime = time.localtime()
IsApiCall = False
currentTime = datetime.now()
afterTime=datetime.now()
layout_duration=0


#import json file parameters here
with open('config.json', 'r') as f:
    distros_dict = json.load(f)
    XiboClient_id = distros_dict['client_id']
    XiboClient_secret=distros_dict["client_secret"]
    XiboUrl=distros_dict["url"]
    XiboDisplaygroup=distros_dict["displaygroup"]
    XiboLayoutId=distros_dict["layoutId"]
    IpCamStreamUrl=distros_dict["ipCamStreamUrl"]
    playerIpAddress=distros_dict["playerIpAddress"]

    print(IpCamStreamUrl)
    # print(xiboclient_id)
    # print(xiboclient_secret)
    # print(xibourl)
    # print(xibodisplaygroup)
    # print(xibolayoutid)
    # sys.exit()
    # url = "'"+XiboClient_id+"'"
    # print(url)




#check lic
def validateLicense():
    # Load the certificate
    with open('certificate.pem', 'rb') as f:
        certificate = f.read()

    # Load the license
    with open('license.lic', 'rb') as f:
        license = License.load(f, b'stech_lic_78324')
        # Verify the license; this will raise License.InvalidSignatureException if
        # the signature is incorrect
        license.verify(certificate)
        if license.data.extra != gma(ip=playerIpAddress):
            print(license.data.extra)
            print(gma(ip=playerIpAddress))
            # shutdown the application and notify user about invalid license
            easygui.msgbox("Your camera module license is invalid please contact to S-Tech team", title="Invalid License!")
            sys.exit()






def __draw_label(img, text, pos, bg_color):
    font_face = cv2.FONT_HERSHEY_SIMPLEX
    scale = .4
    color = (0, 0, 0)
    thickness = cv2.FILLED
    margin = 2
    txt_size = cv2.getTextSize(text, font_face, scale, thickness)

    end_x = pos[0] + txt_size[0][0] + margin
    end_y = pos[1] - txt_size[0][1] - margin

    cv2.rectangle(img, pos, (end_x, end_y), bg_color, thickness)
    cv2.putText(img, text, pos, font_face, scale, color, 1, cv2.LINE_AA)
# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(IpCamStreamUrl)
# video_capture = cv2.VideoCapture("http://192.168.1.20:8080/video")

# Initialize some variables
face_locations = []

while True:
    # Grab a single frame of video
    ret, frame = video_capture.read()

    if ret ==False:
        break
    # Resize frame of video to 1/4 size for faster face detection processing
    small_frame = cv2.resize(frame, (0,0),fx=1,fy=1,interpolation = cv2.INTER_AREA)

    # Find all the faces and face encodings in the current frame of video
    face_locations = face_recognition.face_locations(small_frame, model="hog")
    print(face_locations)
    if  face_locations is ():
        break
    if datetime.now().strftime("%S") == afterTime.strftime("%S"):
        IsApiCall=False
    # Display the results
    i=0
    genders=[]
    ages=()
    for top, right, bottom, left in face_locations:
        # Scale back up face locations since the frame we detected in was scaled to 1/4 size
        top *= 4
        right *= 4
        bottom *= 4
        left *= 4

        # Extract the region of the image that contains the face
        face_image = frame[top:bottom, left:right]
        height,width  = face_image.shape[:2]

        if width>144:
                image='face{}.jpg'.format(i)
                cv2.imwrite(image,face_image)
        if datetime.now().strftime("%S") == afterTime.strftime("%S"):
            IsApiCall=False


        # customization by basit for layout change digisign player
        if IsApiCall is False:
            #check License
            validateLicense()
            # Access Token api 
            url = "http://"+XiboUrl+"/api/authorize/access_token"
            data = {
                'client_id': XiboClient_id,
                'client_secret': XiboClient_secret,
                'grant_type': 'client_credentials'
            }
            response = requests.request("POST", url, data=data)
            obj=json.loads(response.text)
            temp = obj["access_token"]

            # Change layout Api
            url = "http://"+XiboUrl+"/api/displaygroup/"+XiboDisplaygroup+"/action/changeLayout?envelope=1"
            data = {
                'layoutId': XiboLayoutId,
                'changeMode': 'replace'
            }
            headers = {
                'Authorization': 'Bearer '+temp
            }
            response = requests.request("POST", url, headers=headers, data=data)
            print("Layout change = Success")
            IsApiCall = True 

            # Get layout duration api
            url = "http://"+XiboUrl+"/api/layout/status/"+XiboLayoutId+"?envelope=1"
            headers = {
            'Authorization': 'Bearer '+temp
            }
            response = requests.request("GET", url, headers=headers)
            objj=json.loads(response.text)
            temp1 = objj["data"]
            layout_duration=temp1["duration"]
            print("Current layout duration is " +str(layout_duration)+ " second")
            currentTime = datetime.now()
            afterTime = (datetime.now() + timedelta(seconds=layout_duration+10))
            print("Next layout change after "+afterTime.strftime("%H")+":"+afterTime.strftime("%M")+":"+afterTime.strftime("%S"))
        else:
            currentTime=(datetime.now())
            if (currentTime.strftime("%S") == afterTime.strftime("%S")):            
                IsApiCall = False

    #For Vedio display window
    cv2.namedWindow('Video', cv2.WINDOW_NORMAL)
    cv2.imshow('Video', frame)

    # Hit 'q' on the keyboard to quit!
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
Basit Ali
  • 11
  • 1
  • 2
  • Possibly related: https://stackoverflow.com/questions/59168477/cant-find-starting-number-in-the-name-of-file-when-trying-to-read-frames-fr – Zachary Craig May 15 '20 at 13:54

0 Answers0