- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要一些帮助来解决我现在遇到的这个问题。我有 3 张图像,它们只是不同之处相同,它们代表蓝色、绿色和红色。我需要将它们组合起来并得到彩色图像。我正在使用 opencv 和 c++,但现在我遇到了这个问题,我无法弄清楚。
需要:进行边缘检测。
----更新----我写了一些新代码
Sobel(img_r, x, CV_16S, 1, 0);
Sobel(img_r, y, CV_16S, 0, 1);
//Compute the L1 norm
sobel_L1_norm = abs(x)+abs(y);
//Find Sobel max value
minMaxLoc(sobel_L1_norm, &min, &max);
sobel_L1_norm.convertTo(sobel_image, CV_32F, 255.0/(max - min), -min * 255.0/(max - min));
threshold(sobel_image, edgeThreshold, min, 255, THRESH_BINARY);
edgeThreshold.copyTo(img_r_edge);
我得到这个结果 bad example
不过应该是这样的。 correct one
-----完整代码-----
Mat img_r = imread(input_path + "/01.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat img_g = imread(input_path + "/02.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat img_b = imread(input_path + "/03.png", CV_LOAD_IMAGE_GRAYSCALE);
// Edge Images
Mat img_r_edge = Mat::zeros(img_r.size(), CV_8UC1);
Mat img_g_edge = Mat::zeros(img_g.size(), CV_8UC1);
Mat img_b_edge = Mat::zeros(img_b.size(), CV_8UC1);
std::cout << "Step 1 - calculating edge images... ";
// TODO: 1) Calculate the 1st Sobel derivative once in x and once in y direction and combine these two
// (for every channel).
Mat x;
Mat y;
Mat abs_x;
Mat abs_y;
Mat sobel_L1_norm;
Mat sobel_image;
Mat edgeThreshold;
double min, max; //Finding min and max Sobel valuye;
//---------------------------------------------------
Sobel(img_r, x, CV_16S, 1, 0);
Sobel(img_r, y, CV_16S, 0, 1);
//Compute the L1 norm
sobel_L1_norm = abs(x)+abs(y);
//Find Sobel max value
minMaxLoc(sobel_L1_norm, &min, &max);
sobel_L1_norm.convertTo(sobel_image, CV_32F, 255.0/(max - min), -min * 255.0/(max - min));
threshold(sobel_image, edgeThreshold, min, 255, THRESH_BINARY);
edgeThreshold.copyTo(img_r_edge);
//----------------------------------------------------
// 2) Normalize every gradient image and convert the results to CV_8UC1.
// 3) Threshold the retrieved (normalized) gradient images using the parameter "edgeThreshold".
// 4) Save the results in the cv::Mats below.
imwrite(out_r_edge_filename, sobel);
imwrite(out_g_edge_filename, img_g_edge);
imwrite(out_b_edge_filename, img_b_edge);
最佳答案
您正在设定 sobel_image
的阈值有阈值min
.
但是min
将(几乎)永远是 0
,因为它是 sobel_L1_norm
的最小值图像。请注意,没有渐变的像素的值为 0
。在sobel_L1_norm
.
解决这个问题的方法是为阈值选择一个有意义的值。由于您将值标准化为在 [0, 255]
范围内,您可以选择该范围内的一个值(大于 0)。
如果您使用 [0,1]
中的值进行标准化, 在这个区间内取一个值。
您可以使用 normalize(..., NORM_MINMAX)
而不是找到最大值并重新缩放。
还要注意 edgeThreshold
将是 CV_32F
类型的矩阵在调用 threshold
后, 所以它也是 img_r_edge
.使用 imwrite
正确保存图像, 枯萎使用 CV_32F
图片在 [0,1]
范围内, 或 CV_8U
[0,255] 范围内的图像。所以你需要重新缩放 img_r_edge
在范围 [0,1]
, 或将其转换为 CV_8U
.
您在这里混合了很多 OpenCV 类型。 Mat_<Tp>
通常更容易使用确切地知道类型。
您可以随时使用 CV_32F
图片,范围在 [0,1]。
将产生正确输出的代码,以及建议的修改:
#include <opencv2/opencv.hpp>
#include <vector>
using namespace cv;
using namespace std;
int main()
{
Mat3b img = imread(path_to_color_image");
vector<Mat1b> planes;
split(img, planes);
Mat1b img_r = planes[2].clone();
Mat1b img_g = planes[1].clone();
Mat1b img_b = planes[0].clone();
// Edge Images
Mat1b img_r_edge;
Mat1b img_g_edge;
Mat1b img_b_edge;
// TODO: 1) Calculate the 1st Sobel derivative once in x and once in y direction and combine these two
// (for every channel).
Mat1f dx, dy;
Mat1f sobel_L1_norm;
Mat1f sobel_image;
Mat1f edgeThreshold;
double min, max; //Finding min and max Sobel valuye;
//---------------------------------------------------
Sobel(img_r, dx, CV_32F, 1, 0);
Sobel(img_r, dy, CV_32F, 0, 1);
//Compute the L1 norm
sobel_L1_norm = abs(dx) + abs(dy); // Type
// Normalize
normalize(sobel_L1_norm, sobel_image, 0, 1, NORM_MINMAX);
// Use a value different from 'min', which will (almost always) be 0.
double thresh = 0.5;
threshold(sobel_image, edgeThreshold, thresh, 255, THRESH_BINARY);
edgeThreshold.convertTo(img_r_edge, CV_8U);
imwrite("img_r_edge.png", img_r_edge);
return 0;
}
关于c++ - 在 x 方向和 y 方向计算一次 1st Sobel 导数并将这两者结合起来(对于每个 channel ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36155267/
我很好奇为什么以下不起作用。一般select用default:防止死锁,但在这种情况下不是: package main import "fmt" func main () { a := mak
我一生都无法弄清楚如何切换图像排序。图像以 (x,x,3) 格式读取,theano 要求它是 (3,x,x) 格式。我尝试更改顺序numpy.array([img[:,:,i] for i in ra
我正在向 libnl 发送单个 SSID 和频率进行扫描,但我得到了多个扫描结果以及我请求的 SSID 和频率,但我需要单个扫描结果(仅适用于请求的 SSID),如何实现这一点。请帮助我,我也发送了我
我是 Golang 的新手,但正在努力理解这门伟大的语言!请帮帮我.. 我有 2 个 channel 。 “进”和“出” channel in, out := make(chan Work),
例如我有这段代码: package main import ( "fmt" ) func main() { c1 := make(chan interface{}) close
我们使用以下调用来获取经过身份验证的用户的 ChannelID,它适用于大多数情况。一些 YouTube 用户将他们的 channel 连接到 Google+ 信息页,但在这种情况下,我们的一位用户无
case 'sinfo': const sinfo = new Discord.MessageEmbed() .addField('Server Name 🔎 :', message.guild.n
我需要让所有 channel 来创建一个 bunker 命令,这使得所有 channel 都是只读的。 最佳答案 他们变了Client.servers至 Client.guilds在 newer ve
为什么当第二个值通过另一个 go routine 发送并且没有收到发送的第一个值时, channel c 没有缓冲? package main import "fmt" func sum(s []in
据我所知,内置的 split 会将一个 3 channel Mat 拆分为三个 1 channel Mat。结果,这三个 Mat 只是具有一些不同强度的灰度。 我的意图是获得三个 3 channel
如何检测当前的 RAM 配置?我需要询问 Windows RAM 当前是在单 channel 、双 channel 还是四 channel 中运行。 我搜索了很多,并没有在这个网站或其他网站上找到任何
我需要拆分一个多 channel wav 文件并将每个 channel 编码为 mp3 文件。 我知道 gtresamer 的 deinterleave 插件,但我不确定如何将它用于 wav 文件以及
关闭。这个问题需要details or clarity .它目前不接受答案。 想要改进这个问题吗? 通过 editing this post 添加详细信息并澄清问题. 关闭 8 年前。 Improve
我正在尝试运行 Hyperledger Fabric 网络,它由单个订购者、单个对等节点和一个 cli 组成。为了学习启动 Hyperledger Fabric 网络的过程,从创建与加密相关的工件到将
我在 Laravel 中使用事件广播。我正在使用基于角色的通知访问权限。我有用于广播的自定义 auth guard。当用户连接到 channel 时,客户端将具有内部权限的 access_token
我正在编写一个使用 Elixir Channels 来处理实时事件的应用程序。我知道每个客户端将打开 1 个套接字,并且可以在其上多路复用多个 channel 。所以我的应用程序是一个聊天应用程序,其
我有一些 .wav 文件,我想转换它们的频率 (fs) 和 channel 数 (nchannels)。我在jupyter笔记本python3.6上使用ffmpeg。我使用了以下命令并且它有效。 cm
我有一个视频渲染器,它需要两个 H265 流(YUV420),我需要烘焙它们以使它们中的一个与另一个形成 alpha 蒙版。这一切都已解决并且效果很好,但是如果我按照此处的说明进行操作: ffmpeg
我运行此命令以便能够将 udp 直播流传输到可使用正在构建的移动应用程序播放的 http 直播流。 它只是一个只有音频流的流。 ffmpeg -i udp://@localhost:1111 -map
我在我的 discord.js 机器人中创建了 nuke 命令,它创建了具有相同名称、权限、主题等的 channel ,并删除了“原始” channel 。但是有一个问题,如何使 channel 与“
我是一名优秀的程序员,十分优秀!