Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import skvideo
skvideo.setFFmpegPath("C:/Users/User/PycharmProjects/MachineLearning/venv/lib/site-packages/skvideo/io")
import skvideo.io
input_parameters ={}
output_parameters ={}
reader=skvideo.io.FFmpegReader("Cool_Kids.mp4",inputdict=input_parameters,outputdict=output_parameters)
num_frames,height,width,num_channels =reader.getShape()
print(num_frames, height, width, num_channels)
For analyzing Cool_Kids.mp4 video using skvideo library, before I would use
skvideo.setFFmpegPath("C:/Users/User/PycharmProjects/MachineLearning/venv/lib/site-packages/skvideo/io")
I was getting following error:
AssertionError: Cannot find installation of real FFmpeg (which comes with ffprobe).
Then after researching a bit I found this setFFmpegPath command, but got the same error. What part am I missing? There is this link
Cannot find installation of real FFmpeg (which comes with ffprobe), but I can't do more. What should I do?
You have to install FFmpeg command line tool.
It looks like have to install FFmpeg in your system outside of Python (I can't find a way to download ffmpeg.exe and ffprobe.exe using pip install command).
[Note: Installing FFmpeg in Windows, is different from the way described in your link].
You may also take a look at my answer to the following post.
Recommended solution:
Download FFmpeg (include FFprobe) executable for Windows (download the statically linked version).
Place ffmpeg.exe and ffprobe.exe in the same folder.
For example at: c:/FFmpeg/bin
Set setFFmpegPath to the above folder:
import skvideo
skvideo.setFFmpegPath("C:/FFmpeg/bin")
import skvideo.io
...
Note:
You may choose to place ffmpeg.exe and ffprobe.exe in the folder:
C:/Users/User/PycharmProjects/MachineLearning/venv/lib/site-packages/skvideo/io.
Related
I was wondering if you have used the library "trimesh" in python. It looks quite useful, but right now im having some trouble with the method "Trimesh.spli()" on the last line of the code attached. the code was working fine up to that line, which is suppose to return a list of trimesh objects.
However, when I try to run this code, I get the error ImportError: no graph engines available!
Do you know how can I set up a graph engine? or if there is any turnaround this issue?
Thanks for your support,
Regards
import numpy as np
import trimesh
# Load the stl files into the script
mesh = trimesh.load('Path_to_STL_file')
mesh2 = trimesh.load('Path_to_raw_material_in_STL')
# Confirm both files are closed
assert mesh.is_watertight
assert mesh2.is_watertight
#Boolean operation
mesh3 = trimesh.Trimesh.difference(mesh2,mesh)
list_mesh = trimesh.Trimesh.split(mesh3)
I found the issue. The library does not install all dependancies unless you ask for it. Usually, it only requires numpy.
One option to install most of the dependancies is:
pip install trimesh[easy]
or, if that doesn't solve it, you could use:
pip install trimesh[all]
You need to also install either scipy or networkx to satisfy the graph engine dependency. There's a comment in the source code that networkx is 5-10 times slower than scipy so it's probably best to install scipy. If you're using pip then it's
pip install scipy
or if you're using conda:
conda install scipy
I am trying to convert lots of xyz file to raster, using gdal.Translate in Spyder. But I came across several problems.
I first try with convert only one xyz file. Code is like:
import os
from osgeo import gdal,osr
xyz = '1x1m_678494.xyz'
xyzraster = '1x1m_678494.tif'
translateoptions = gdal.TranslateOptions(projWin='EPSG:3879')
gdal.Translate(xyzraster,xyz,options=translateoptions)
the result is i can get a tif file, but without spatial reference. And there was no error or warning message. Then i thought it might relate to the gdal package. i found some similar issues here https://gis.stackexchange.com/questions/142215/gdal-translate-projection-errorhttps://github.com/conda/conda/issues/4050,I did set the GDAL_DATA to the path 'C:\Program Files\Anaconda3\Library\share\gdal'. This didn't solve my problem. checked my gdal version is 2.3.3 with python 3.7.3. I am trying to remove this gdal and install the newest version gdal 3.0.4 using conda. But there seems to be a incompatible issue.
In the same time, i found there is also independent install for GDAL, http://cartometric.com/blog/2011/10/17/install-gdal-on-windows/. This tutorial has one step to set the GDAL_DATA and GDAL_DRIVER_PATH, but the paths are different from the GDAL_DATA installed by conda. I am very confused. Will the independent installed gdal works different from the conda installed gdal? Or i just need one of them?
Then i leave the spatial reference issue behind, and tried convert multiple xyz to a geotiff. But got some other issues. code is like:
import os
import gdal
import glob
path = 'D:\\Data\\1m\\'
gdal.BuildVRT(path+'out.vrt',glob.glob(path+'\\*.xyz'))
gdal.Translate(path+'out.tif',path+'out.vrt')
The error is ValueError: Received a NULL pointer.
Can anyone help me out, please?
** gdal.TranslateOptions(projWin=(zip(ulx,uly,lrx,lry)),projWinSRS='EPSG:3879')
Is where the first part went wrong.
I have installed spacepy using the following command (MacOS Mojave):
pip install git+https://github.com/spacepy/spacepy.git
But I keep getting this error while trying to from spacepy import pycdf:
Exception: Cannot load CDF C library; checked . Try 'os.environ["CDF_LIB"] = library_directory' before import.
I have tried following the directions from their website, but it seems like those directions are a bit outdated.
You can do something like:
import os
os.environ["CDF_LIB"] = "~/CDF/lib" # Give the path of the cdf library
# e.g. in this case the library is in your home directory.
Before doing:
from spacepy import pycdf
Source of the error can be found on this SpacePy website.
The cdf library is available here.
Basically, you need to set up the CDF_LIB (if pycdf has a trouble finding it) before importing the module. You can read the documentation here.
I am trying to use OpenCV for Python 3 for the first time. To install, I simply typed "pip3 install opencv-python" into the terminal. When I do this, I see in Finder (I'm on a Mac), that in /usr/local/lib/python3.7/site-packages, I now have a new folder called "cv2". This is strange. Why isn't it cv3, as I used pip3? I do not know.
When I try to import cv2 from python3, it says "No module named 'cv2'". Luckily StackOverflow already has a solution: if I first change directories like: "cd /usr/local/lib/python3.7/site-packages" then I will be able to open cv2. I do not know why this step is necessary for OpenCV. I don't have to do this to "import numpy" for example; "numpy" does not care what directory I start from, and it is listed like just another module like cv2.
Anyways, I change directory to site-packages, start python3, and I import cv2. Now there is a new error. This time cv2 is found, but it says:
"from .cv2 import *
ModuleNotFoundError: No module named 'cv2.cv2'"
For the record, I also have Python 2.7. If I try "cd /usr/local/lib/python2.7/site-packages" and then start Python 2.7, I can import cv2. This is ok, but I want to use OpenCV with Python3.
Let me summarize.
(1) How can I get cv2 or cv3 to import when I start from any directory? Is this ever possible?
(2) How can I get cv3 for python3? cv2 seems to be problematic in python3 because because there is no "cv2.cv2"
The only thing we need to know here is, that 2 in cv2 is not a version. cv2 uses API of C++ while cv uses C API. Version of it is constantly updating being inside CV2.
There is no cv3 there's only import cv2 that opencv older or latest that is updated for old python or latest.
The Context:
I'm trying to use the package trackpy for research. I'm on a Mac and I'm using (mostly) Spyder. I’m following the trackpy walkthrough (https://soft-matter.github.io/trackpy/v0.3.2/tutorial/walkthrough.html) and I’m trying to use it on a tif file. Here’s my code:
#Install trackpy (https://soft-matter.github.io/trackpy/v0.3.2/installation.html)
!conda update conda --yes
!conda install -c conda-forge trackpy --yes
#Use trackpy (trackpy walkthrough: https://soft-matter.github.io/trackpy/v0.3.2/tutorial/walkthrough.html)
from __future__ import division, unicode_literals, print_function
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import pims
import trackpy as tp
#Install libtif for pims.Tiffstack, per the README (which leads to this link: http://nbviewer.jupyter.org/github/soft-matter/pims/blob/master/examples/loading%20video%20frames.ipynb)
!conda install libtiff --yes
frames = pims.TiffStack("/Users/(my username)/Documents/TSVIEW_Test_5_Grey_1.tif", as_grey=True)
The Problems: When I first wrote the code, I got the error:
TypeError: init() got an unexpected keyword argument 'as_grey'
According to the trackpy walkthrough, it should take as_grey as an argument.
However, when I restarted my computer, I got a different error message (without any code changes as far as I can tell):
/anaconda3/lib/python3.5/site-packages/tifffile/tifffile.py:2113: UserWarning: invalid ImageJ metadata or corrupted file
warnings.warn('invalid ImageJ metadata or corrupted file')
Again, I didn't change the code between restarting it.
Interestingly, when I tried this code in a different python-running software, I got the first error again. I tried it in Google Colab. The only changes I made to the code were using pip instead of conda (Colab only supports pip), downloading the additional dependencies needed for pip per the trackpy install page (https://soft-matter.github.io/trackpy/v0.3.2/installation.html), and uploading the file to Colab per the 'External data: Drive, Sheets, and Cloud Storage' Colab guide.
Things I've tried:
I’ve researched both problems. For the first, I found a page that asked the same problem (pims.Video parameter issue in Spyder), but the only solution provided is "an installation issue" where certain modules are "from the wrong source.” If this is right (is it?), what does it mean? How can I install the modules from the right source?
For the second, I found from the pims website that pims is based on the the tifffile dependency (http://soft-matter.github.io/pims/v0.4/tiff_stack.html). I then found the code that brought the error message (line 2415 from the tifffile.py page https://github.com/scikit-image/scikit-image/blob/master/skimage/external/tifffile/tifffile.py), but I still don’t know how to solve it.
How can I solve these errors?