嗨,我是一个初学者,尝试学习openFrameworks,并且在运行代码时遇到此错误。我一直在环顾四周,找不到解决方案,请帮忙。它在xcode上运行,并且我以前设法运行过以前的应用程序。
ofApp.h
#pragma once
#include "ofMain.h"
#include "opencv2/opencv.hpp"
class ofApp : public ofBaseApp {
public:
void setup();
void update();
void draw();
void keyPressed(int key) {};
void keyReleased(int key) {};
void mouseMoved(int x, int y) {};
void mouseDragged(int x, int y, int button) {};
void mousePressed(int x, int y, int button) {};
void mouseReleased(int x, int y, int button) {};
void windowResized(int w, int h) {};
void dragEvent(ofDragInfo dragInfo) {};
void gotMessage(ofMessage msg) {};
ofEasyCam cam;
cv::VideoCapture cap;
cv::Size cap_size;
int number_of_frames;
vector<cv::Mat> frame_list;
ofImage image;
cv::Mat frame;
vector<ofMesh> mesh_list;
};
ofApp.cpp
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openFrameworks");
ofBackground(239);
ofSetColor(255);
ofEnableDepthTest();
this->cap.open("D:\\video\\image51.mp4");
this->cap_size = cv::Size(256, 144);
this->image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR);
this->frame = cv::Mat(cv::Size(this->image.getWidth(), this->image.getHeight()), CV_MAKETYPE(CV_8UC3, this->image.getPixels().getNumChannels()), this->image.getPixels().getData(), 0);
this->number_of_frames = 25 * 27;
for (int i = 0; i < this->number_of_frames; i++) {
cv::Mat src, tmp;
this->cap >> src;
if (src.empty()) {
return;
}
cv::resize(src, tmp, this->cap_size);
cv::cvtColor(tmp, tmp, cv::COLOR_BGR2RGB);
this->frame_list.push_back(tmp);
}
for (int i = 0; i < 128; i++) {
ofMesh mesh;
mesh.addVertex(glm::vec3(-128, -72, 0));
mesh.addVertex(glm::vec3(128, -72, 0));
mesh.addVertex(glm::vec3(128, 72, 0));
mesh.addVertex(glm::vec3(-128, 72, 0));
mesh.addTexCoord(glm::vec3(0, 0, 0));
mesh.addTexCoord(glm::vec3(256, 0, 0));
mesh.addTexCoord(glm::vec3(256, 144, 0));
mesh.addTexCoord(glm::vec3(0, 144, 0));
mesh.addIndex(0); mesh.addIndex(1); mesh.addIndex(2);
mesh.addIndex(0); mesh.addIndex(2); mesh.addIndex(3);
this->mesh_list.push_back(mesh);
}
}
//--------------------------------------------------------------
void ofApp::update() {
ofSeedRandom(39);
}
//--------------------------------------------------------------
void ofApp::draw() {
this->cam.begin();
ofRotateX(180);
ofRotateY(ofGetFrameNum() * 0.5);
for (auto& mesh : this->mesh_list) {
auto location = glm::vec3(ofRandom(-500, 500), ofRandom(-500, 500), ofRandom(-500, 500));
//int n = ofMap(ofNoise(glm::vec4(location, ofGetFrameNum() * 0.005)), 0, 1, 0, this->number_of_frames);
int n = int(ofRandom(1000) + ofGetFrameNum()) % this->number_of_frames;
this->frame_list[n].copyTo(this->frame);
this->image.update();
ofPushMatrix();
ofTranslate(location);
this->image.bind();
mesh.draw();
this->image.unbind();
ofPopMatrix();
}
this->cam.end();
}
main.cpp
#include "ofApp.cpp"
#include "ofApp.h"
//========================================================================
int main() {
ofSetupOpenGL(1280, 720, OF_WINDOW);
ofRunApp(new ofApp());
}
我收到2个错误:“没有匹配函数可调用'ofRunApp'”和“命名空间'cv'中没有名为'VideoCapture'的类型”
我正在尝试学习和开发与此类似的艺术项目,因此我从https://github.com/junkiyoshi/Insta20200217中获取了代码。任何帮助将不胜感激
请把#include <opencv2/videoio.hpp>
添加到您的main.cpp中