Python Windows 10 64bit - FFMPEG for trackpy - python-3.x

Similar problem to 'Python Moviepy installation problems (windows 7x64)' except the solution provided did not work.
I have windows 10, 64bit. Every time I attempt to run the following line of code:
frames = pims.Video('exp9_short.avi')
I get the blue Windows 10 error: This app can't run on your PC
as well as the Python error:
OSError: Could not load meta information
=== stderr ===
Access is denied.
I have tried multiple versions from 'https://ffmpeg.zeranoe.com/builds/' to no avail.
I don't know if other image processing tools will work with trackpy, or if there are any alternatives to trackpy.
I would really appreciate some advice.

I solved this problem by processing each image with OpenCV2
vid0 = cv2.VideoCapture('exp9_short.avi')
numfr = int(vid0.get(cv2.CAP_PROP_FRAME_COUNT))
for n1 in range(0,numfr-1):
success,img = vid0.read(n1) #read video frame by frame
if n1==0:
h, w, cols = img.shape #image size
fr=np.zeros([h,w,3,numfr-1]) #frames
frgr=np.zeros([h,w,numfr-1]) #grayscale fr
frgrbi=frgr #binarized frgr
fr[:,:,:,n1]=img
frgr[:,:,n1]=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

Related

Reading file using python is not working properly in Linux

I'm running a python code where we read a fixed width file, which we extracted from ftp server. the code is working on windows without any issue. but when i am running the same code in the linux ec2 instance it's giving an error saying that "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 1819: invalid start byte". but the same code running in windows without any error.since i am not aware about the encoding type of the source file i am passing the encoding type as None. And this also working fine in windows but when we running the code in linux its giving an error saying that "encoding type None is not recognize".
i am using the codecs library to read the file and python version that i am using is 3.7.3
with codecs.open("recode.dat",encoding=None,errors='replace') as open_src:
with open("target_file.dat", 'w+',encoding=None) as open_tgt:
for src_rec in open_src:
new_rec = ''
for f_length in data_type_length:
f_length = int(f_length)
field = '"' + src_rec[:f_length].strip() + '"|'
new_rec += (field)
src_rec = src_rec[f_length:]
open_tgt.write(new_rec[:-1] + '\n')

jaydebeapi connection terminates without any exception or error | unable to investigate further

I followed the usage steps as per the example, after the second step of defining "conn" the script terminates and comes back to the command line without raising any errors o warnings or exception.
I am not able to identify what went wrong, has anyone faced this issue with jaydebeapi?
Sharing the libraries/environment details I am using and screenshot.
Example:
import jaydebeapi
conn = jaydebeapi.connect("org.hsqldb.jdbcDriver",
... "jdbc:hsqldb:mem:.",
... ["SA", ""],
... "/path/to/hsqldb.jar",) --------my script terminates at this step
curs = conn.cursor()
Environment:
Windows 10 64bit
Python 3.7.4
JayDeBeApi==1.1.1
JPype1==0.6.3
sasl==0.2.1
thrift==0.10.0
thrift-sasl==0.3.0
Jar = hive-jdbc-1.2.1-standalone.jar
Resolution is appreciated.
Are you using same (i.e. 64 bit) versions of programms? Reinstallation from python 32 to python 64 helped me with the same problem.

zoom out firefox 52 on redhat 6.8 using selenium python 3.4

I have redhat 6.8 where firefox is 52.8 esr and python is 3.4 and geckodriver is 18
My requirement is to zoom out the browser and take a screenshot of the required part of the webpage.
I tried below methods:
browser.execute_script("$('#values').css('zoom', 5);") ( This didnt work )
driver.execute_script("document.body.style.zoom = '200%'") ( This is applicable only for chrome )
element.send_keys(Keys.CONTROL + "-") ( This didnt work )
Below two methods I'm not getting appropriate results
driver.execute_script('document.body.style.MozTransform = "scale(0.8)";')
driver.execute_script('document.body.style.MozTransformOrigin="3 4";')
Below worked on MAC with firefox 52.8, but not working on redhat 6.8 with firefox 52.8 geckodriver is 18
element = driver.find_element_by_class_name('col-10')
location = element.location
size = element.size
png = driver.get_screenshot_as_png() # saves screenshot of entire page
im = Image.open(BytesIO(png)) # uses PIL library to open image in memory
left = location['x']
top = location['y']
right = location['x'] + size['width']
bottom = location['y'] + size['height']
im = im.crop((left, top, 2000, 2900)) # defines crop points
im.save('screen.png')
Note: Using firefox 52.8 esr because on redhat 6.8 we cannot upgrade to latest firefox and cant install chrome
Please help me to resolve the issue. I almost google search couldn't find an appropriate solution. Thanks in advance.

Python Script got ERROR when switch from Windows to Linux

I write a Python script on Windows and work pretty well, now I just installed "elementary Os" that is a Ubuntu based distro, but some how when I start the script it just crashed... I dont really now how to fixed it.
I let u a part of the script making problem:
memos=open(str(os.getcwd())+'\\LOG\\tres.txt','w')
menf='3)PRESION LATERAL DEL SUELO DE RELLENO\n Ka = '+str(round(Ka,2))+'\nP = '+str(round(P,2))+'\nY = '+str(round(Y,2))+'''
\nHm = '''+str(round(Hm,2))+'\nPm = '+str(round(Pm,2))+'\nYm = '+str(round(Ym,2))
memos.write(menf)
memos.close()
So the deal should be...
memos=open(str(os.getcwd())+'\\LOG\\tres.txt','w')
Because show me an error...
UnicodeEncodeError: 'ascii' codec can't encode character '\xba' in position 199: ordinal not in range(128)
Now, when I change for...
memos=open(str(os.getcwd())+'/LOG/tres.txt','w')
It got me another error...
FileNotFoundError: [Errno 2] No such file or directory: '/home/jojaror/Documentos/Scripts de Python/LOG/tres.txt'
I tryed to solve at my own, but i can't... so, if anyway could help me on this it would be helpful.

How to load a raster layer using PyQGIS?

Although there are some posts on this matter, there is no answer in anyone of them. This is why I am asking it again.
One post I found was https://gis.stackexchange.com/questions/68032/raster-layer-invalid
I read information from the following link: https://hub.qgis.org/wiki/17/Arcgis_rest .
I used the command: gdal_translate "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true" s.xml -of WMS. And it generated the file successfully. However, when I try to open the file and assuming the provider is wms, the code report layer is invalid.
The code I used is:
file = QFileDialog.getOpenFileName(self,
"Open WMS", ".", "WMS (*.xml)")
fileInfo = QFileInfo(file)
# Add the layer
layer = QgsRasterLayer(file, fileInfo.fileName(),"wms")
if not layer.isValid():
print "Failed to load."
return
I just choose the file from the dialog box.
I also tried the other command: qgis.utils.iface.addRasterLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true","raster") by using the following code:
layer = QgsRasterLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true", "layer")
if not layer.isValid():
print "Failed to load."
return
It also report "Failed to load". The original command can be run successfully in QGIS python command line. Also, if I try to enter the code in python console, the layer.isValid() would return true. It is just not working in standalone script.
Answer can be found here: https://gis.stackexchange.com/questions/120823/how-to-load-a-wms-layer-using-pyqgis.
Basically, it is just a version problem. If you have qgis previous than v2.6, it would not work. But it is fixed for 2.6
If it is still not working for you, you most likely have problem for environment variable settings.
This is working for me for single band image.I am using python 2.7 and QGIS 2.0.1 .You can load any raster layer like wms,tiff (single band or multiband) etc. using this.:
def ifile(self):
global fileName
fileName = str(QtGui.QFileDialog.getOpenFileName(self.iface.mainWindow(),"Open Raster File",'C:\\',"raster files(*.tif *.tiff *.TIF *.TIFF *.IMG *.img )"))
if len(fileName) is 0:
return
else:
self.inFileName = fileName;
filelayer = QgsRasterLayer(fileName,os.path.basename(fileName))
if filelayer == None or filelayer.bandCount() != 1:
self.errorMessage = "Not a DEM Image"
QMessageBox.information(self.iface.mainWindow(), "Error", self.errorMessage)
else:
#f=open(str(self.inFileName))
self.dlg.lineEdit.setText(self.inFileName)
if filelayer.isValid():
QgsMapLayerRegistry.instance().addMapLayer(filelayer)
pass

Resources