C_and_CPP 板


LINE

开发平台(Platform) Win10 编译器 VC++ 2019+目标环境(跟开发平台不同的话需列出) 额外使用到的函数库(Library Used): (Ex: OpenCV 4.5.3 ) 问题(Question) 没有合适的建构函式存在,无法从"char"转换为”cv::Mat” 喂入的资料(Input): 预期的正确结果: show出 raw档的图 错误结果(Wrong Output): 没有合适的建构函式存在,无法从"char"转换为”cv::Mat” 程式码(Code): #include <iostream> #include <stdio.h> #include <opencv2/opencv.hpp> #include <fstream> using namespace cv; using std::ofstream; using std::ifstream; using std::fstream; using std::ios; int main() { fstream rawlena; rawlena.open("lena_256.raw", ios::binary); rawlena.seekg(0, ios::end); int length = rawlena.tellg(); rawlena.seekg(0, ios::beg); char* buffer = new char[length]; Mat rawlenaimage = (256,256, CV_8UC1, buffer); imshow("photo", rawlenaimage); waitKey(5000); } 补充说明(Supplement): 我上网爬了许多文看到大家都用类似的方法,可是我找了一整天还是找不到我的问题在 哪里,只好拜托大家帮忙了 ---- Sent from BePTT on my Xiaomi M2102J20SG -- int main() { FILE* input_file; unsigned char* img_lena = new unsigned char[256*256]; fread(img_lena, 1, 256*256, input_file); Mat mat_lena(256, 256, CV_8UC1, img_lena); imshow("lena in opencv", mat_lena); } 我後来改用这样写,然後成功了。 还有其实是不能用opencv的,只是因为我真的不知道要怎麽不用opencv才能把照片show出来,我网路上怎麽找也找不到相关的写法,抱歉我有点烂...



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 27.240.170.9 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1632904564.A.A8E.html
1F:推 nh60211as: Mat rawImage = Mat(...) 才对09/29 16:45
2F:→ hope2801: 收到09/29 16:49
3F:→ hope2801: 非常谢谢您的帮忙,帮忙我解决了一部份的问题09/29 17:18
4F:→ hope2801: 但是我现在遇到了我没看过的问题09/29 17:18
5F:→ hope2801: 0x00007FFCEAA14F99 中 (於 showphoto.exe) 发生未处理09/29 17:19
6F:→ hope2801: 的例外状况: Microsoft C++ 发生例外状况: std::bad_a09/29 17:19
7F:→ hope2801: rray_new_length (记忆体位置 0x000000982CF5F7F0)。09/29 17:19
8F:→ hope2801: 这是在throw_bad_alloc.cpp档里09/29 17:20
9F:→ hope2801: #else // ^^^ Managed ^^^ // vvv Native vvv //09/29 17:20
10F:→ hope2801: __declspec(noreturn) void __CRTDECL __scrt_thr09/29 17:20
11F:→ hope2801: ow_std_bad_alloc()09/29 17:20
12F:→ hope2801: {09/29 17:20
13F:→ hope2801: throw std::bad_alloc{};09/29 17:20
14F:→ hope2801: }09/29 17:20
15F:→ hope2801: __declspec(noreturn) void __CRTDECL __scrt_thr09/29 17:20
16F:→ hope2801: ow_std_bad_array_new_length()09/29 17:20
17F:→ hope2801: {09/29 17:20
18F:→ hope2801: throw std::bad_array_new_length{};09/29 17:20
19F:→ hope2801: }09/29 17:20
20F:→ hope2801: #endif09/29 17:20
21F:→ hope2801: https://i.imgur.com/bFNOkC0.jpg09/29 17:21
22F:→ hope2801: 请问一下这个bug是什麽问题?09/29 17:22
23F:→ hope2801: char* buffer = new char[length];09/29 17:36
24F:→ hope2801: 我是此行程式有问题,可是我看不出来我错在哪里09/29 17:36
25F:→ nh60211as: 你tellg()回传值是啥?感觉你这程式码还会有很多问题09/29 17:57
26F:→ hope2801: 我的tellg()回传25970-1给length09/29 18:08
27F:→ hope2801: 我的raw图是一个大小为256x256的深度为8的灰阶图09/29 18:08
28F:→ hope2801: https://i.imgur.com/itcDqee.jpg09/29 18:10
29F:→ nh60211as: 这什麽数字啊,我看不太懂09/29 18:29
30F:→ F04E: 只不过是show个raw档需要动用到OpenCV??这年头作业真好写09/29 20:18
31F:→ nh60211as: 我知道25970是什麽了,那是'er'多字元字元的数值09/29 20:24
32F:→ nh60211as: tellg()回传的是-1,代表你读档根本就失败了09/29 20:28
※ 编辑: hope2801 (27.246.37.129 台湾), 10/04/2021 21:41:28







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP