当前位置:首页 » 编程语言 » pythonopencv图片

pythonopencv图片

发布时间: 2023-03-30 00:33:11

python OpenCV视频拆分图片代码

# coding:utf-8

import cv2

import numpy as np

import os

print("1")

vc = cv2.VideoCapture("123.mp4")

C = 1

print("2")

if vc.isOpened():

rVal, frame = vc.read()

else:

print("3")

rVal = False

while rVal:

print(C)

if C % 1000 == 0: # every 5 fps write frame to img

path='./image/'+str(C)+'.jpg'

cv2.imwrite(path, frame)

# cropped001 = frame2[0:300,300:600] #y change from 0 to 300 x change from 300 to 600

# cv2.im write('./cropped/'+str(c)+'001.jpg',cropped001)

print(C)

cv2.waitKey(1)

C = C + 1

vc.release()

② opencv和python下,对图片的读取程序报错如何解决

1、需要用到其他模块的函数,如:

for i in range(20) #循环次数

image=cv2.imread("D:\picture\%d.jpg"%(i))#路径自己选择。

2、可以先升级你的pip,另外看看你的版本是否匹配,包括py版本和32位64位。

3、关于python下使用opencv读取图像。首先需要导入opencv包,上面说的那个Ipython并没有opencv包,所以想使用的请先正确导入opencv包再说,至于怎么导入,先下载个opencv包,里面有关于python的opencv包。
以下照片是关于Ipython的运行界面:

③ 基于Python的opencv从csv文件中读取图片的问题

报错异常说明
参数类型不正确

④ 为什么用Python的openCV读取图片与PIL读取的图片像素值会不一样

经测试,同一张图片,使用 PIL和 OpenCv库读取的数据是一样的(经过BGR转成RGB):

建议:可以尝试更新 PIL或是 OpenCv库。

本机测试环境: Python 3.7+Pillow 6.2 +opencv-python 4.1

⑤ python opencv 显示图片 未响应

整个项目的结构图:

编写DetectFaceDemo.java,代码如下:

[java] view
plainprint?

package com.njupt.zhb.test;

import org.opencv.core.Core;

import org.opencv.core.Mat;

import org.opencv.core.MatOfRect;

import org.opencv.core.Point;

import org.opencv.core.Rect;

import org.opencv.core.Scalar;

import org.opencv.highgui.Highgui;

import org.opencv.objdetect.CascadeClassifier;

//

// Detects faces in an image, draws boxes around them, and writes the results

// to "faceDetection.png".

//

public class DetectFaceDemo {

public void run() {

System.out.println("\nRunning DetectFaceDemo");

System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());

// Create a face detector from the cascade file in the resources

// directory.

//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("森段并lbpcascade_frontalface.xml").getPath());

//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());

//注意:源程序的路径会多打印一个燃竖‘/’,因此总是出现如下错误

/*

* Detected 0 faces Writing faceDetection.png libpng warning: Image

* width is zero in IHDR libpng warning: Image height is zero in IHDR

* libpng error: Invalid IHDR data

*/

//因此,我们将第一个字符去掉

String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);

CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);

Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));

// Detect faces in the image.

// MatOfRect is a special container class for Rect.

MatOfRect faceDetections = new MatOfRect();

faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("此迹Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.

for (Rect rect : faceDetections.toArray()) {

Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));

}

// Save the visualized detection.

String filename = "faceDetection.png";

System.out.println(String.format("Writing %s", filename));

Highgui.imwrite(filename, image);

}

}
package com.njupt.zhb.test;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

//
// Detects faces in an image, draws boxes around them, and writes the results
// to "faceDetection.png".
//
public class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");
System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
// Create a face detector from the cascade file in the resources
// directory.
//CascadeClassifier faceDetector = new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//Mat image = Highgui.imread(getClass().getResource("lena.png").getPath());
//注意:源程序的路径会多打印一个‘/’,因此总是出现如下错误
/*
* Detected 0 faces Writing faceDetection.png libpng warning: Image
* width is zero in IHDR libpng warning: Image height is zero in IHDR
* libpng error: Invalid IHDR data
*/
//因此,我们将第一个字符去掉
String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);
Mat image = Highgui.imread(getClass().getResource("we.jpg").getPath().substring(1));
// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);

System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

// Draw a bounding box around each face.
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 255, 0));
}

// Save the visualized detection.
String filename = "faceDetection.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}

3.编写测试类:

[java] view
plainprint?

package com.njupt.zhb.test;

public class TestMain {

public static void main(String[] args) {

System.out.println("Hello, OpenCV");

// Load the native library.

System.loadLibrary("opencv_java246");

new DetectFaceDemo().run();

}

}

//运行结果:

//Hello, OpenCV

//

//Running DetectFaceDemo

///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml

//Detected 8 faces

//Writing faceDetection.png
package com.njupt.zhb.test;
public class TestMain {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java246");
new DetectFaceDemo().run();
}
}
//运行结果:
//Hello, OpenCV
//
//Running DetectFaceDemo
///E:/eclipse_Jee/workspace/JavaOpenCV246/bin/com/njupt/zhb/test/lbpcascade_frontalface.xml
//Detected 8 faces
//Writing faceDetection.png

⑥ 基于python语言的opencv如何把图片中指定区域截取出来

3-切割轮廓

(这是我网站找的一篇 blog, 亲测有效)

⑦ python3中如何加载图片

答: 如下所示。

  • 可利用opencv-Python接口,使用imread()函数,那么导入名为example的图片的例子如下所示。

import cv2



image = cv2.imread('./example.png')

  • 也可以使用matplotlib.pyplot中的pyplot模块,具体例子如下所示。

import matplotlib.pyplot as plt



import matplotlib.image as mpimg



import numpy as np



image = mpimg.imread('./example.png')



print image.shape



plt.imshow(image) #调用imshow函数

在这里只是说了两种方法,希望能够帮助到你。

⑧ python-opencv怎么在不影响图片中其他颜色的情况下,将黑色背景变成白色背景

设前景色为白色,选择--色彩范围,点选黑色,作反相处理,调整色阶至满意,局部细节用画笔修整一下即可。

⑨ opencv和python下,运行对图片的读取程序时出现的问题!!!

1、需要姿顷用到其他模块的函数,如:

for i in range(20) #循环次数

image=cv2.imread("D:\picture\%d.jpg"%(i))#路径自迹掘陆己选择。

2、可以先升级你的pip,另外看看你的版本是否匹配,包括py版本和32位64位。

3、关于python下使用opencv读取图像。首先散毁需要导入opencv包,上面说的那个Ipython并没有opencv包,所以想使用的请先正确导入opencv包再说,至于怎么导入,先下载个opencv包,里面有关于python的opencv包。
以下照片是关于Ipython的运行界面:

⑩ python opencv如何存图片到指定路径按图上的会存到python_work文件夹

如图,修改倒数第四行的内容为:
cv2.imwrite('F:/xxx/yyy/' + str(c) + '.jpg', frame)

即可将图片存储到 F 盘的 xxx\yyy 目录中,这里按照你的需要修改即可

热点内容
瑞纳自动买哪个配置 发布:2024-11-02 20:18:45 浏览:559
sql复制数据库结构 发布:2024-11-02 20:18:43 浏览:582
yaf编译 发布:2024-11-02 20:06:30 浏览:126
小数除以大数怎么算法 发布:2024-11-02 19:44:59 浏览:810
安卓手机如何重新设置付款密码 发布:2024-11-02 19:31:44 浏览:980
多巴胺3mg静脉注射怎么配置 发布:2024-11-02 19:25:50 浏览:618
源码之城 发布:2024-11-02 19:24:43 浏览:513
国军标环境存储要求 发布:2024-11-02 19:23:04 浏览:107
sql多行转多列 发布:2024-11-02 19:17:52 浏览:119
linuxftp文件夹权限 发布:2024-11-02 19:17:03 浏览:899