我在OpenCV android 2.4.11的例子下工作,它使用相机检测面部.我没有在找到的脸上画一个矩形,而是试图在脸上放一个面具(png图像).但是为了在脸上显示图像,png图像带有透明度的黑色背景.
FdActivity.java
public void onCameraViewStarted(int width, int height) {
mGray = new Mat();
mRgba = new Mat();
//Load my mask png
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.mask_1);
mask = new Mat();
Utils.bitmapToMat(image, mask);
}
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) { …Run Code Online (Sandbox Code Playgroud) 我正在用 Python 学习 OpenCV。我试图以 PNG 格式更改图片的颜色,但我遇到了 PNG 背景的一些问题(图像具有透明背景)。
当我将其更改为灰度时,背景已更改为黑色——我的图片不再透明。我想要的是保持图片的透明背景。
原图:
我的代码:
img = cv2.imread('line.png',cv2.IMREAD_UNCHANGED)
cv2.imshow('line',img)
cv2.waitKey()
Run Code Online (Sandbox Code Playgroud)
输出图像:
期望的输出:
边框图像周围的白色应该是透明的。我怎么能做到这一点?
如果我有像这样的面具

我有一个图像(大小与面具相同)就像

我想突出显示图像中的蒙版。如果我使用其他语言,我只是

如您所见,结果图像有一个透明的红色显示蒙版。我希望在 OpenCV 中实现这一点。所以我写了这段代码
#include <opencv.hpp>
using namespace cv;
using namespace std;
int main() {
Mat srcImg = imread("image.jpg");
Mat mask = imread("mask.jpg", IMREAD_GRAYSCALE)>200;
for(int i=0;i<srcImg.rows;i++)
for(int j=0;j<srcImg.cols;j++)
if(mask.at<uchar>(i, j)==255)
circle(srcImg, Point(j,i), 3, Scalar(0, 0, 128,128));
imshow("image",srcImg);
waitKey();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是如您所见,我在 中使用了 alpha 值Scalar,但它不是透明的 red。

也许这是因为srcImg只有 3 个频道。我有两个关于这个的问题
circle逐像素绘制才能完成此操作?我正在研究对脏图像文档进行去噪。我想创建一个数据集,其中添加合成噪声来模拟现实世界的混乱伪影。模拟污垢可能包括咖啡渍、褪色的太阳斑、折角的页面、大量皱纹等等。我该怎么做呢?
干净图像示例:
添加合成噪声后:
如何随机获得上面显示的图像?
image machine-learning image-processing random-seed data-augmentation
在我的项目中,我从视频中提取了帧,在另一个文件夹中,我有每个帧的地面实况。\n我想将视频每帧的地面实况图像(在我的例子中,它是显着性预测地面实况)映射到其相关帧图像。作为示例,我有以下框架:
\n\n以下是真实掩码:
\n\n以下是真实值在框架上的映射。
\n\n我怎样才能做到这一点。另外,我有两个文件夹,每个文件夹内都有几个文件夹,每个文件夹内都有存储的帧。如何对这些批量数据进行操作?
\n这是我的文件夹的层次结构:
\n框架_文件夹:文件夹_1、文件夹_2、......
\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 frames\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 601 (601 and 602 and etc are folders that in the inside there are image frames that their name is like 0001.png,0002.png, ...)\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 602\n .\n .\n .\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 700\n\n\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ground truth\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 601 (601 and 602 and etc are folders that in the inside there are ground truth masks that their name is like 0001.png,0002.png, ...)\n \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 602\n …Run Code Online (Sandbox Code Playgroud) 我有一个 rgba 格式的图像,其中包含 (0,0,0) 个黑色,我想将这些 (0,0,0) 像素中的每一个都转换为透明。图像已经有一个 alpha 通道,我不知道如何为一个像素激活 alpha 通道。我尝试将 alpha 通道值设置为 0,但到目前为止还没有奏效:
for y in range(len(blur)):
for x in range(len(blur[0])):
if blur[y][x][0] == 0 and blur[y][x][1] == 0 and blur[y][x][2] == 0:
blur[y][x][3] = 0
Run Code Online (Sandbox Code Playgroud)
另外,如何使用 numpy 来优化这个嵌套的 for 循环?
我想,如图所示混合两个图像这里.
这是我的整个代码
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
int main( int argc, char** argv )
{
double beta; double input;
Mat src1, src2, dst;
/// Ask the user enter alpha
std::cout<<" Simple Linear Blender "<<std::endl;
std::cout<<"-----------------------"<<std::endl;
src1 = imread("face.jpg");
src2 = imread("necklace1.png");
if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
if( !src2.data ) { printf("Error loading src2 \n"); return -1; }
double alpha = 0.1; // something
int min_x = ( (src1.cols …Run Code Online (Sandbox Code Playgroud)