shihy_ 2022-01-09 15:21 采纳率: 60%
浏览 366
已结题

DevC++报错“ 'cv' is not a namespace-name”应该怎么办啊?

代码:

#define GLUT_DISABLE_ATEXIT_HACK
#include <gl\glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <SOIL.h>
#include<iostream>
#include<opencv2\opencv.hpp>    //可混合处理,加上尺寸调整函数
using namespace cv;
using namespace std;
 
GLuint texture[6];
GLfloat xRot, yRot, zRot;
 
int LoadGLTextures(){   //加载纹理到opengl
    int Status = 0;
    char *picFile[6] = { "image/up.png","image/down.png","image/left.png",   //注意先调整图片大小
        "image/right.png","image/far.png","image/timi.png" };
    for (int i = 0;i < 6;++i){
        texture[i] = SOIL_load_OGL_texture(
            picFile[i],
            SOIL_LOAD_AUTO,
            SOIL_CREATE_NEW_ID,
            SOIL_FLAG_INVERT_Y);
        if (texture[i] == 0)
            Status = 0;
        glBindTexture(GL_TEXTURE_2D, texture[i]);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    }
    return Status;
}
 
int init(){
    glEnable(GL_TEXTURE_2D);
    glCullFace(GL_BACK);    //剔除背面
    glEnable(GL_CULL_FACE);
 
    if (!LoadGLTextures()) {
        return 0;
    }
    glShadeModel(GL_SMOOTH);   //平滑着色
    glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
    glClearDepth(1.0f);
 
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    return 1;
}
void cube() {    //绘制
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
    glEnd();
 
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f);
    glEnd();
 
    glBindTexture(GL_TEXTURE_2D, texture[2]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f);
    glEnd();
 
    glBindTexture(GL_TEXTURE_2D, texture[3]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, -1.0f, -1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
    glEnd();
 
    glBindTexture(GL_TEXTURE_2D, texture[4]);
    glBegin(GL_QUADS);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f);
    glEnd();
 
    glBindTexture(GL_TEXTURE_2D, texture[5]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
    glEnd();
}
void display(){   //动态显示
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);   //平移
    glRotatef(xRot, 1.0f, 0.0f, 0.0f);   //旋转
    glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    glRotatef(zRot, 0.0f, 0.0f, 1.0f);
    cube();
    xRot += 0.02f;   //调节速度
    yRot += 0.02f;
    zRot += 0.02f;
    glutSwapBuffers();
}
void showCube() {     //初始静止显示
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);   
    cube();
    glutSwapBuffers();
}
void showStop() {   //结束后显示
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -5.0f);   
    glRotatef(xRot, 1.0f, 0.0f, 0.0f);  
    glRotatef(yRot, 0.0f, 1.0f, 0.0f);
    glRotatef(zRot, 0.0f, 0.0f, 1.0f);
    cube();
    glutSwapBuffers();
}
 
void reshape(int w, int h){
    if (h == 0)   //至少一个像素
        h = 1;
    glViewport(0, 0, (GLsizei)w, (GLsizei)h);
    glMatrixMode(GL_PROJECTION);   //投影模式
    glLoadIdentity(); 
    gluPerspective(60.0f, (GLfloat)w / (GLfloat)h, 1, 100);   //设置透视
    glMatrixMode(GL_MODELVIEW);    //模型视图矩阵
    glLoadIdentity();  
}
 
void keyboard(unsigned char key, int x, int y){   //可用键盘控制旋转
    switch (key) {
    case 's':   //开始旋转
        glutDisplayFunc(display);
        glutIdleFunc(display);
        break;
    case 'e':  //结束旋转
        GLfloat mari[16];
        glGetFloatv(GL_MODELVIEW_MATRIX, mari);
        for (int i = 0; i < 16; i++) {
            cout << mari[i] << " ";
            if ((i + 1) % 4 == 0) {
                cout << endl;
            }
        }
        exit(0);
        break;
    }
}
 
int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(200, 200);
    glutCreateWindow("Show");
    init();
    glutDisplayFunc(showCube);
    glutKeyboardFunc(keyboard);
 
    glutReshapeFunc(reshape);
 
    glClearColor(1.0f, 0.0f, 1.0f, 1.0f);   
    glutMainLoop();
    return 0;
}

把第8行注释掉会显示“连接器返回错误代码1”,不注释掉会报标题的错误提示,请问是不是和没有配置SOIL.lib有关系啊?

img

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2022-01-09 15:32
    关注

    using namespace cv;
    那cv到底是不是命名空间啊?
    你没有#include "cv.h"吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 1月9日

悬赏问题

  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥20 unity内置语言切换的按钮设置
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?
  • ¥15 html5 qrcode 扫描器