Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

Update loadSaveImage.cpp #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Problem Sets/Problem Set 4/loadSaveImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <opencv2/opencv.hpp>
#include <vector>
#include "cuda_runtime.h"

using namespace std;
//The caller becomes responsible for the returned pointer. This
//is done in the interest of keeping this code as simple as possible.
//In production code this is a bad idea - we should use RAII
Expand All @@ -13,7 +13,7 @@ void loadImageHDR(const std::string &filename,
float **imagePtr,
size_t *numRows, size_t *numCols)
{
cv::Mat image = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR | CV_LOAD_IMAGE_ANYDEPTH);
cv::Mat image = cv::imread(filename.c_str(), 1 | 3);
if (image.empty()) {
std::cerr << "Couldn't open file: " << filename << std::endl;
exit(1);
Expand Down Expand Up @@ -43,7 +43,7 @@ void loadImageRGBA(const std::string &filename,
uchar4 **imagePtr,
size_t *numRows, size_t *numCols)
{
cv::Mat image = cv::imread(filename.c_str(), CV_LOAD_IMAGE_COLOR);
cv::Mat image = cv::imread(filename.c_str(), 1);
if (image.empty()) {
std::cerr << "Couldn't open file: " << filename << std::endl;
exit(1);
Expand All @@ -60,7 +60,7 @@ void loadImageRGBA(const std::string &filename,
}

cv::Mat imageRGBA;
cv::cvtColor(image, imageRGBA, CV_BGR2RGBA);
cv::cvtColor(image, imageRGBA, COLOR_BGR2RGBA);

*imagePtr = new uchar4[image.rows * image.cols];

Expand All @@ -85,7 +85,7 @@ void saveImageRGBA(const uchar4* const image,
sizes[1] = numCols;
cv::Mat imageRGBA(2, sizes, CV_8UC4, (void *)image);
cv::Mat imageOutputBGR;
cv::cvtColor(imageRGBA, imageOutputBGR, CV_RGBA2BGR);
cv::cvtColor(imageRGBA, imageOutputBGR, COLOR_RGBA2BGR);
//output the image
cv::imwrite(output_file.c_str(), imageOutputBGR);
}
Expand Down