TypeError: VideoWriter() missing required argument 'frameSize' (pos 5) with opencv-python ==4.4.0.42 - video-capture

I want to create VideoWriter with the following code:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter('out.mp4',fourcc,fps,(frame_width,frame_height))
but i get the error:
TypeError: VideoWriter() missing required argument 'frameSize' (pos 5)
when i change my code to:
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get another error:
TypeError: VideoWriter() missing required argument 'apiPreference' (pos 2)
so i change my code to :
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(filename='out.mp4',apiPreference=0,fourcc=fourcc,fps=fps,frameSize=(frame_width,frame_height))
i get error:
TypeError: VideoWriter() missing required argument 'params' (pos 6)
How could i solve it? Could anyone tell me how to use the api:VideoWriter()?Thanks a lot

ok, the following code works for me :
frame_num = int(Cap.get(cv2.CAP_PROP_FRAME_COUNT))
frame_width = int(Cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(Cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video_writer = cv2.VideoWriter(result,fourcc,fps,(frame_width,frame_height))
the type of Cap.get(cv2.*) is float, so i change it to integer

fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter(path,apiPreference = 0,fourcc = fourcc, fps = 30,frameSize = (256,256) )
for i in range(len(predictions)):
out.write((img_as_ubyte(predictions[i])))
out.release()
it did worked for me
used skimage's image_as_ubyte to convert float to int.

Related

Creating a fixed list of constants in pyomo: set, param or variable?

I am trying to make an array of fixed constants (model.oldweights) that I subtract from the variable x in this model, but I am getting an error:
import pyomo.environ as pyo
from pyomo.core.expr.numeric_expr import LinearExpression
model = pyo.ConcreteModel()
model.nVars = pyo.Param(initialize=4)
model.N = pyo.RangeSet(model.nVars)
model.x = pyo.Var(model.N, within=pyo.Reals)
model.er = [1, 1, 3, 1]
model.oldweights = pyo.Param(model.N, initialize=[0,0,0,0])
model.linexp = LinearExpression(constant=0,linear_coefs=model.er,linear_vars=[model.x[i] for i in model.N])
model.c1 = pyo.Constraint(rule=sum(model.x[i] for i in model.N)==0)
model.c2 = pyo.Constraint(rule=sum(abs(model.x[i]) for i in model.N)==2)
model.c3 = pyo.Constraint(rule=sum(abs(model.x[i]-model.oldweights[i]) for i in model.N)<=0.03)
model.obj = pyo.Objective(expr = model.linexp, sense = maximize)
results = SolverFactory('ipopt', executable='/content/ipopt').solve(model)
results.write()
ERROR:pyomo.core:Rule failed for Param 'oldweights' with index 0:
KeyError: "Index '0' is not valid for indexed component 'oldweights'"
I have tried to make the list as a set, param and variable and nothing works.

converting pyspark dataframe fail on 'None Type' object

I have a pyspark dataframe 'data3' with many columns. I am trying to run kmeans on it except the first two columns, when I run my code , tasks always fails on TypeError: float() argument must be a string or a number, not 'NoneType' What am I doing wrong?
def f(x):
rel = {}
#rel['features'] = Vectors.dense(float(x[0]),float(x[1]),float(x[2]),float(x[3]))
rel['features'] = Vectors.dense(float(x[2]),float(x[3]),float(x[4]),float(x[5]),float(x[6]),float(x[7]),float(x[8]),float(x[9]),float(x[10]),float(x[11]),float(x[12]),float(x[13]),float(x[14]),float(x[15]),float(x[16]),float(x[17]),float(x[18]),float(x[19]),float(x[20]),float(x[21]),float(x[22]),float(x[23]),float(x[24]),float(x[25]),float(x[26]),float(x[27]),float(x[28]),float(x[29]),float(x[30]),float(x[31]),float(x[32]),float(x[33]),float(x[34]),float(x[35]),float(x[36]),float(x[37]),float(x[38]),float(x[39]),float(x[40]),float(x[41]),float(x[42]),float(x[43]),float(x[44]),float(x[45]),float(x[46]),float(x[47]),float(x[48]),float(x[49]))
return rel
data= data3.rdd.map(lambda p: Row(**f(p))).toDF()
kmeansmodel = KMeans().setK(7).setFeaturesCol('features').setPredictionCol('prediction').fit(data)
TypeError: float() argument must be a string or a number, not 'NoneType'
Your error comes from converting the xs to float because you probably have missing values
rel['features'] = Vectors.dense(float(x[2]),float(x[3]),float(x[4]),float(x[5]),float(x[6]),float(x[7]),float(x[8]),float(x[9]),float(x[10]),float(x[11]),float(x[12]),float(x[13]),float(x[14]),float(x[15]),float(x[16]),float(x[17]),float(x[18]),float(x[19]),float(x[20]),float(x[21]),float(x[22]),float(x[23]),float(x[24]),float(x[25]),float(x[26]),float(x[27]),float(x[28]),float(x[29]),float(x[30]),float(x[31]),float(x[32]),float(x[33]),float(x[34]),float(x[35]),float(x[36]),float(x[37]),float(x[38]),float(x[39]),float(x[40]),float(x[41]),float(x[42]),float(x[43]),float(x[44]),float(x[45]),float(x[46]),float(x[47]),float(x[48]),float(x[49]))
return rel
You can create a flag to convert each x to float when there is a missing values. For example
list_of_Xs = [x[2], x[3], x[4], x[5], x[6],etc. ]
for x in list_of_Xs:
if x is not None:
x = float(x)
Or use rel.dropna()

ValueError: time data 'dateConstat' does not match format

my code:
annee_now = datetime.datetime.now().strftime("%Y")
dateConstat = fields.Date(default= fields.Date.today())
fiche_emi_Struc=self.env['conformite.fiche'].search_count([(datetime.datetime.strptime(("dateConstat"),"%Y-%m-%d").strftime("%Y"),'=',annee_now)])
my message error:
ValueError: time data 'dateConstat' does not match format '%Y-%m-%d'
How Resolve it?
thanks.
Change the code like this:
annee_now = datetime.datetime.now().strftime("%Y")
dateConstat = fields.Date.today()
fiche_emi_Struc = self.env['conformite.fiche'].search_count([
((dateConstat).strftime("%Y"), '=', annee_now)
])

pyautogui.center, TypeError: 'NoneType' object is not subsriptable

I'm trying to code a program to take care of some boring stuff. When I try to use pyautogui.center() I get an error. Here is an example of the code and the error:
c = pyautogui.locateOnScreen('sample.png')
d = pyautogui.center((c))
d = pyautogui.center((c))
File "C:\Users\\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pyscreeze\__init__.py",
line 404, in center
return (coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2)) TypeError: 'NoneType' object is not subscriptable
This could be because of image is not found on screen too. But try this
sample_image = pyautogui.locateAllOnScreen('sample.png')
center_of_image = pyautogui.center(sample_image)
pyautogui.mouseDown(center[0], center[1])
pyautogui.mouseUp(center[0], center[1])

genfromtxt in Python-3.5

I am trying to fix a data set using genfromtxt in Python 3.5. But I keep getting the next error:
ndtype = np.dtype(dict(formats=ndtype, names=names))
TypeError: data type not understood
This is the code I'm using. Any help will be appreciated!
names = ["country", "year"]
names.extend(["col%i" % (idx+1) for idx in range(682)])
dtype = "S64,i4" + ",".join(["f18" for idx in range(682)])
dataset = np.genfromtxt(data_file, dtype=dtype, names=names, delimiter=",", skip_header=1, autostrip=2)
dtype = "S64,i4" + ",".join(["f18" for idx in range(682)])
is going to produce something like:
s64,i4f18,f18,f18,f18...
Note the lack of a comma after the i4.