Unable to resolve the name cv.getOptimalNewCameraMatrix.
I do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
endI do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
end I do not solve this problem. I am trying to solve in many ways. Please anyone help me.
I find this problem:
Unable to resolve the name cv.getOptimalNewCameraMatrix.
Error in undistortion>undistorb_images (line 92)
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0,
[width,height]);
Error in undistortion (line 1)
undistorb_images([], []);
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "images";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
%image_files = [];
files = [dir(fullfile(image_path,’*.jpg’)); dir(fullfile(image_path,’*.png’)); dir(fullfile(image_path,’*.jpeg’)); dir(fullfile(image_path,’*.PNG’))];
%files = dir(fullfile(image_path, ‘*.(jpg|png)’));
L = length(files);
% kk=0;
% for i=1:L
% file=files(i).name;
% image_files = [image_files, file]
%
%
% end
%disp(image_files)
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(files)
for i=1:L
file=files(i).name;
image_file_name = [image_file_name,file];
%disp(image_file_name)
image = imread(image_path + "" + file);
%disp(image);
% [imagePoints, boardSize] = detectCheckerboardPoints(image_file_name);
% squareSize = 29;
% worldPoints = generateCheckerboardPoints(boardSize, squareSize);
%
% I = readimage(image, 1);
% imageSize = [size(I,1), size(I,2)];
% [params, ~, estimationErrors] = estimateCameraParameters(imagePoinsts, worldPoints, ‘ImageSize’);
[height, width] = size(image);
%disp(string(height) + " " + string(width))
%[newCameraMatrix,w] = cv.getOptimalNewCameraMatrix(cameraMatrix, dist, [width,height]);
[newcameramtx, roi] = cv.getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
%dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
% imageFileNames{i} = fullfile(matlabroot,’toolbox’,’vision’,’visiondata’,’calibration’,’webcam’,image_file_name);
% [imagePoints,~,imagesUsed] = detectCheckerboardPoints(imageFileNames, ‘PartialDetections’, false);
% imageFileNames = imageFileNames(imagesUsed);
% for i = 1:numel(imageFileNames)
% I = imread(imageFileNames{i});
% subplot(2, 2, i);
% imshow(I);
% hold on;
% plot(imagePoints(:,1,i),imagePoints(:,2,i),’ro’);
% end
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(string(height) + " " + string(width));
imwrite("undistortion/" + file, dst);
end
end
end image processing, matlab MATLAB Answers — New Questions