Linux平台下动态链接库.so转换成windiws平台下.dll文件并使用python调用

问题起因:

在运行PointNet的可视化程序时,作者只提供了linux平台下的动态链接库程序源码,自己的windows平台下无法调用。发现是动态链接库的文件格式不对,遂学习如何将.so文件转换成.dll文件(PS:前提是你有文件的.cpp源码)

第一步新建C++动态链接库项目

在这里插入图片描述
将pch.h文件的内容改为如下:


#ifndef PCH_H
#define PCH_H

// 添加要在此处预编译的标头
#include "framework.h"

#endif //PCH_H
//定义宏
#ifdef IMPORT_DLL
#else
#define IMPORT_DLL extern "C" _declspec(dllimport) //指的是允许将其给外部调用
#endif

// 改为你所需要的链接库函数
IMPORT_DLL void render_ball(int h, int w, unsigned char* show, int n, int* xyzs, float* c0, float* c1, float* c2, int r);

第二步:重写dllmain.cpp文件

// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

struct PointInfo {
	int x, y, z;
	float r, g, b;
};
void render_ball(int h, int w, unsigned char* show, int n, int* xyzs, float* c0, float* c1, float* c2, int r) {
	r = max(r, 1);
	vector<int> depth(h * w, -2100000000);
	vector<PointInfo> pattern;
	for (int dx = -r; dx <= r; dx++)
		for (int dy = -r; dy <= r; dy++)
			if (dx * dx + dy * dy < r * r) {
				double dz = sqrt(double(r * r - dx * dx - dy * dy));
				PointInfo pinfo;
				pinfo.x = dx;
				pinfo.y = dy;
				pinfo.z = dz;
				pinfo.r = dz / r;
				pinfo.g = dz / r;
				pinfo.b = dz / r;
				pattern.push_back(pinfo);
			}
	double zmin = 0, zmax = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			zmin = xyzs[i * 3 + 2] - r;
			zmax = xyzs[i * 3 + 2] + r;
		}
		else {
			zmin = min(zmin, double(xyzs[i * 3 + 2] - r));
			zmax = max(zmax, double(xyzs[i * 3 + 2] + r));
		}
	}
	for (int i = 0; i < n; i++) {
		int x = xyzs[i * 3 + 0], y = xyzs[i * 3 + 1], z = xyzs[i * 3 + 2];
		for (int j = 0; j<int(pattern.size()); j++) {
			int x2 = x + pattern[j].x;
			int y2 = y + pattern[j].y;
			int z2 = z + pattern[j].z;
			if (!(x2 < 0 || x2 >= h || y2 < 0 || y2 >= w) && depth[x2 * w + y2] < z2) {
				depth[x2 * w + y2] = z2;
				double intensity = min(1.0, (z2 - zmin) / (zmax - zmin) * 0.7 + 0.3);
				show[(x2 * w + y2) * 3 + 0] = pattern[j].b * c2[i] * intensity;
				show[(x2 * w + y2) * 3 + 1] = pattern[j].g * c0[i] * intensity;
				show[(x2 * w + y2) * 3 + 2] = pattern[j].r * c1[i] * intensity;
			}
		}
	}
}

// 具体内容改为你的文件内容

第三步点击debug按钮生成.dll文件,文件目录如下

在这里插入图片描述

如何使用python调用不在赘述,需要再码

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值